Cod sursa(job #2531436)

Utilizator vmnechitaNechita Vlad-Mihai vmnechita Data 26 ianuarie 2020 12:00:01
Problema Aria Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <bits/stdc++.h>

using namespace std;

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

struct Punct
{
    long double x, y;
};

Punct v[100005];

bool crt ( Punct a, Punct b );
long double aria_triunghi ( Punct a, Punct b, Punct c );

int main()
{
    int n, i;
    long double aria = 0;

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

    sort ( v + 1 , v + n + 1, crt );
    v[n+1] = v[1];
    for ( i = 1 ; i <= n ; i++ ) aria += aria_triunghi ( v[0], v[i], v[i+1] );

    fout << setprecision ( 5 ) << fixed << aria;

    return 0;
}

bool crt ( Punct a, Punct b )
{
    if ( aria_triunghi ( v[0], a, b ) > 0 ) return 1;

    return 0;
}

long double aria_triunghi ( Punct a, Punct b, Punct c )
{
    b.x -= a.x;
    b.y -= a.y;
    c.x -= a.x;
    c.y -= a.y;
    a.x = a.y = 0;

    return ( b.x * c.y - b.y * c.x ) / 2;
}