Cod sursa(job #3271090)

Utilizator razvan242Zoltan Razvan-Daniel razvan242 Data 25 ianuarie 2025 10:12:27
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <float.h>
#include <fstream>
#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);
    }
    points.push_back(points[0]);
}

long double modul(long double x) {
    return x > 0.0 ? x : -x;
}

void solve() {
    long double aria = 0;

    for (int i = 0; i < points.size() - 1; ++i) {
        aria += points[i].x * points[i + 1].y - points[i + 1].x * points[i].y;
    }
    fout << fixed << modul(aria) / 2.0;
}

int main() {
    read();
    solve();
    return 0;
}