Cod sursa(job #987741)

Utilizator manutrutaEmanuel Truta manutruta Data 21 august 2013 14:00:48
Problema Aria Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
# include <iostream>
# include <fstream>
# include <iomanip>
using namespace std;

# define MAXN 100010

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

int n;
long double x[MAXN], y[MAXN];
long double aria = 0;

long double abs(long double x) {
    if (x < 0) {
        return -x;
    }
    return x;
}

int main()
{
    f >> n;
    for (int i = 1; i <= n; i++) {
        f >> x[i] >> y[i];
    }

    x[n + 1] = x[1];
    y[n + 1] = y[1];
    for (int i = 1; i <= n; i++) {
        aria += (long double)0.5 * (x[i] * y[i + 1] - y[i] * x[i + 1]);
    }

    g << setprecision(10) << abs(aria);

    f.close();
    g.close();
    return 0;
}