Cod sursa(job #933320)

Utilizator andreifirstCioara Andrei Ioan andreifirst Data 29 martie 2013 20:25:00
Problema Aria Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>
#include <iomanip>
using namespace std;

ifstream f("aria.in"); ofstream g("aria.out");

struct point{
	long double x, y;
};

point v[100005];
long double surface;
int i, j, n;

/** 
  *       | x1 y1 1 |
  * det = | x2 y2 1 |
  *       | x3 y3 1 |
  *
  **/

inline long double det (long double x1, long double y1, long double x2, long double y2, long double x3, long double y3){
	return x1*y2 + x2*y3 + x3*y1 - x1*y3 - x2*y1 - x3*y2;
}

int main(){
	f>>n;
	f>>v[1].x>>v[1].y;
	for (i=2; i<=n; i++){
		f>>v[i].x>>v[i].y;
		surface += det(0, 0, v[i-1].x, v[i-1].y, v[i].x, v[i].y);
	}

	surface += det(0, 0, v[n].x, v[n].y, v[1].x, v[1].y);
	
	if (surface < 0) surface *=-1;
	
	// We did not divided the determinants by 2 in previous computations
	surface /= 2.0;
	
	g<<fixed<<setprecision(6);
	g<<surface;
}