Cod sursa(job #3270912)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 24 ianuarie 2025 20:49:30
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <fstream>
#include <cmath>
#include <iomanip>
#include <vector>

using namespace std;

ifstream fin("aria.in");
ofstream fout("aria.out");

struct Point {
    long double x, y;
};

int n;
vector<Point> points;

void read() {
    fin >> n;
    long double x, y;
    for (int i = 1; i <= n; ++i) {
        fin >> x >> y;
        points.emplace_back(x, y);
    }
}

int nextIndex(int currentIndex) {
    return currentIndex == n - 1 ? 0 : currentIndex + 1;
}

long double computeDeterminant(const Point& a, const Point& b) {
    return a.x * b.y - b.x * a.y;
}

void solve() {
    long double area = 0;
    for (int i = 0; i < n; ++i) {
        area += computeDeterminant(points[i], points[nextIndex(i)]);
    }
    fout << fixed << setprecision(7) << area / 2.0;
}

int main() {
    read();
    solve();

    return 0;
}