Cod sursa(job #1871176)

Utilizator k.bruenDan Cojocaru k.bruen Data 7 februarie 2017 10:51:50
Problema Aria Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1 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 minx, miny;

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 (int i = 0; i < n; i++) {
		pair<double, double> temp;
		in >> temp.first >> temp.second;
		if (temp.first < minx) minx = temp.first;
		if (temp.second < miny) miny = temp.second;
		coord.push_back(temp);
	}

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