Cod sursa(job #2510545)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 16 decembrie 2019 21:15:20
Problema Aria Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.18 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));
}
double arie_tri(punct a, punct b, punct c){
    return ( (a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x) );
}
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 += arie_tri(p[i], p[(i + 1) % n], {0, 0});
        ///fout << trig(p[i], p[(i + 1) % n]) << ' '  << arie_tri(p[i], p[(i + 1) % n], {0, 0})<<  '\n';
    }
    if(arie < 0 ) arie *= -1;
    fout << setprecision(5) << fixed << arie / 2;
    return 0;
}