Cod sursa(job #1586986)

Utilizator cristina_borzaCristina Borza cristina_borza Data 1 februarie 2016 19:18:53
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <set>

#define NMAX 100005
#define se second
#define fi first
#define d double
#define l long

using namespace std;

ifstream f("aria.in");
ofstream g("aria.out");

pair <l d , l d> a[NMAX];
int n;

l d ans;

l d arie(pair <l d , l d> x , pair <l d , l d> y);

int main(){
    f >> n;
    for(int i = 1 ; i <= n ; ++i) {
        f >> a[i].fi >> a[i].se;
    }

    for(int i = 1 ; i < n ; ++i) {
        ans += arie(a[i] , a[i + 1]);
    }

    ans += arie(a[n] , a[1]);

    if(ans < 0) {
        ans = -ans;
    }

    ans /= 2;

    g << setprecision(10) << fixed << ans;
    return 0;
}

l d arie(pair <l d , l d> x , pair <l d , l d> y) {
    return x.fi * y.se - y.fi * x.se;
}