Cod sursa(job #1801736)

Utilizator Diana22Diana Lucaci Diana22 Data 9 noiembrie 2016 16:32:01
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
/*#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
*/
#include <cstdio>
#include <iostream>
#include <cmath>
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("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int n;
	double aria = 0;
	cin >> n;
	point points[100];
	for (int i = 0; i < n; i++) {
		cin >> 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;
		}
	}
	cout << aria;
	return 0;
}