Pagini recente » Cod sursa (job #975766) | Rating Bogdan Oprisiu (EmeraldGames3) | Cod sursa (job #1549062) | Cod sursa (job #1799708) | Cod sursa (job #963591)
Cod sursa(job #963591)
#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;
}