Pagini recente » Cod sursa (job #1781196) | Cod sursa (job #1023660) | Cod sursa (job #1615936) | Cod sursa (job #3193735) | Cod sursa (job #1801759)
/*#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
*/
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;
struct point {
double x, y;
};
bool ccw(point a, point b, point c) {
return (a.x * b.y + b.x * c.y + a.y*c.x - a.x * c.y - a.y *b.x - c.x*b.y) > 0;//ccw
}
double arie(point a, point b, point c) {
return 0.5 * abs(a.x * b.y + b.x * c.y + a.y * c.x - a.x * c.y - a.y *b.x - c.x*b.y);
}
int main()
{
//freopen("aria.in", "r", stdin);
//freopen("aria.out", "w", stdout);
ifstream f("aria.in");
ofstream g("aria.out");
int n;
double aria = 0;
f >> n;
point points[100];
for (int i = 0; i < n; i++) {
f >> points[i].x >> points[i].y;
}
for (int i = 0; i < n - 2; i++) {
double aux = arie(points[i], points[i + 1], points[i + 2]);
if (ccw(points[i], points[i + 1], points[i + 2])) {
aria += aux;
}
else {
aria -= aux;
}
}
g << aria;
return 0;
}