Cod sursa(job #963591)

Utilizator tudorv96Tudor Varan tudorv96 Data 17 iunie 2013 20:57:20
Problema Aria Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.87 kb
#include <fstream>
#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;

#define x first
#define y second
#define add push_back

typedef pair <double, double> punct;
typedef vector <punct> poligon;

poligon P;
int n;

double abs(double x) {
	return ((x > -x) ? x : -x);
}

double min(double x, double y) {
	return ((x > y) ? y : x);
}

double arie(punct A, punct B, punct C) {
	return abs((B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y));
}

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

int main() {
	fin >> n;
	punct P0;
	P0.y = (1 << 20);
	for (int i = 0; i < n; ++i) {
		punct p;
		fin >> p.x >> p.y;
		P0.y = min(P0.y, p.y);
		P0.x += p.x;
		P.add(p);
	}
	P0.x /= n;
	fin.close();
	double A = 0;
	for (int i = 0; i < n; ++i)
		A += arie(P0, P[i], P[(i + 1) % n]);
	fout << fixed << setprecision(5) << abs(A / 2);
	fout.close();
	return 0;
}