Cod sursa(job #3039537)

Utilizator lolismekAlex Jerpelea lolismek Data 28 martie 2023 17:43:47
Problema Aria Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.91 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#include <iomanip>

#define double long double

using namespace std;

string filename = "aria";

#ifdef LOCAL
    ifstream fin("input.in");
    ofstream fout("output.out");
#else
    ifstream fin(filename + ".in");
    ofstream fout(filename + ".out");
#endif

const int NMAX = 1e5;

struct Point{
    double x, y;
}v[NMAX + 1];

double area(Point a, Point b, Point c){
    return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y);
}

signed main(){

    int n;
    fin >> n;

    for(int i = 1; i <= n; i++){
        fin >> v[i].x >> v[i].y;
    }

    double A = 0;
    for(int i = 1; i + 1 <= n; i++){
        A += area({0, 0}, v[i], v[i + 1]);
    }
    A += area({0, 0}, v[n], v[1]);

    fout << fixed << setprecision(5);
    fout << A / (2.0) << '\n';

    return 0;
}