Cod sursa(job #2510505)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 16 decembrie 2019 20:23:06
Problema Aria Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
ifstream fin("aria.in");
ofstream fout("aria.out");
struct punct{
    int x, y;
}p[MAXN];
int trig(punct a, punct b){
    if((a.x * b.y) - (b.x * a.y) < 0) return -1;
    return 1;
}
double dist(punct a, punct b){
    return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double heron(punct A, punct B, punct C){
    double a , b , c, p;
    c = dist(A, B);
    a = dist(B, C);
    b = dist(C, A);
    p = (a + b + c) / 2;
    return sqrt(p * (p - a) * (p - b) * (p - c));
}
int main()
{
    ios::sync_with_stdio(false);
    fin.tie(0); fout.tie(0);
    int n; fin >> n;
    double arie = 0;
    for(int i = 0; i < n; ++i){
        fin >> p[i].x >> p[i].y;
    }
    for(int i = 0; i < n; ++i){
        arie += trig(p[i], p[(i + 1) % n]) * heron(p[i], p[(i + 1) % n], {0, 0});
    }
    fout << setprecision(5) << fixed << arie;
    return 0;
}