Cod sursa(job #1800119)

Utilizator valiro21Valentin Rosca valiro21 Data 7 noiembrie 2016 13:04:26
Problema Aria Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std;

double getArea (double lx, double ly, double x, double y) {
	//ly = translate (ly);
	//y = translate (y);

	double X = x - lx;
	return X * (ly + y) / 2.;
}

int main () {
	int n;
	double x, y, lx, ly, x0, y0, a = 0, k;
	ifstream cin ("aria.in");
	ofstream cout ("aria.out");

	cin >> n;
	if (n == 1) {
		cout << fixed << setprecision (6) << a << '\n';
		return 0;
	}
	cin >> lx >> ly;
	x0 = lx; y0 = ly;
	for (int i = 1; i < n; i++) {
		cin >> x >> y;
		a += getArea (lx, ly, x, y);
		lx = x;
		ly = y;
	}
	a += getArea (lx, ly, x0, y0);
	cout << fixed << setprecision(6) << abs(a) << '\n';
	return 0;
}