Cod sursa(job #1871118)

Utilizator TimitocArdelean Andrei Timotei Timitoc Data 7 februarie 2017 10:34:16
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <cstdio>
#define MAXN 100100

using namespace std;

struct pct
{
    double x, y;
    pct (double _x = 0, double _y = 0)
    {
        x = _x;
        y = _y;
    }
};

int n;
double sol;
pct a[MAXN];

void citire()
{
    scanf("%d", &n);
    double x, y;
    for (int i = 1; i <= n; i++)
	{
        scanf("%lf %lf", &x, &y);
		a[i] = pct(x, y);
	}
}

double signedProduct(pct e, pct f)
{
    return 0.5 * (e.x * f.y - f.x * e.y);
}

void solve()
{
	for (int i = 1; i < n; i++)
		sol += signedProduct(a[i], a[i+1]);
	sol += signedProduct(a[n], a[1]);
}

int main()
{
    freopen("aria.in", "r", stdin);
    freopen("aria.out", "w", stdout);

    citire();
	solve();
	printf("%lf", sol);

    return 0;
}