Cod sursa(job #1871269)

Utilizator k.bruenDan Cojocaru k.bruen Data 7 februarie 2017 11:19:45
Problema Aria Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
#include <iomanip>
using std::pair;
using std::vector;

std::ifstream in("aria.in");
std::ofstream out("aria.out");

int n;
vector< pair<double, double> > coord;
double aria;

double mod(double thing) { if (thing < 0) thing = -thing; return thing; }

int main(void) {
	std::ios::sync_with_stdio(false);

	in >> n;
	coord.reserve(n);
	for (double i = 0; i < n; i++) {
		pair<double, double> temp;
		in >> temp.first >> temp.second;
		coord.push_back(temp);
	}

	for (double i = 0; i < n - 1; i++) {
		double h = coord[i + 1].first - coord[i].first;
		double baze = coord[i + 1].second + coord[i].second;
		aria += (((double)(h * baze)) / 2);
	}
	{
		double h = coord[0].first - coord[n - 1].first;
		double baze = coord[0].second + coord[n - 1].second;
		aria += (((double)(h * baze)) / 2);
	}
	
	out << std::setprecision(10.5) << mod(aria);
}