Cod sursa(job #531630)

Utilizator feelshiftFeelshift feelshift Data 9 februarie 2011 23:24:59
Problema Reuniune Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.07 kb
// http://infoarena.ro/problema/reuniune
#include <fstream>
#include <cmath>
using namespace std;

#define x first
#define y second

ifstream in("reuniune.in");
ofstream out("reuniune.out");

struct rectangle {
	pair<long long,long long> downLeft;
	pair<long long,long long> upRight;
};

rectangle intersection(rectangle first,rectangle second);
long long area(rectangle myRectangle);
long long perimeter(rectangle myRectangle);

rectangle first,second,third;

int main() { 
	in >> first.downLeft.x >> first.downLeft.y >> first.upRight.x >> first.upRight.y;
	in >> second.downLeft.x >> second.downLeft.y >> second.upRight.x >> second.upRight.y;
	in >> third.downLeft.x >> third.downLeft.y >> third.upRight.x >> third.upRight.y;

	out << area(first) + area(second) + area(third)
		- area(intersection(first,second))
		- area(intersection(second,third))
		- area(intersection(first,third))
		+ area( intersection (intersection(second,third),first) );

	out << " ";

	out << perimeter(first) + perimeter(second) + perimeter(third)
		- perimeter(intersection(first,second))
		- perimeter(intersection(second,third))
		- perimeter(intersection(first,third))
		+ perimeter( intersection (intersection(second,third),first) );

	return (0);
}

rectangle intersection(rectangle first,rectangle second) {
	rectangle result;

	result.downLeft.x = max(first.downLeft.x,second.downLeft.x);
	result.downLeft.y = max(first.downLeft.y,second.downLeft.y);

	result.upRight.x = min(first.upRight.x,first.upRight.x);
	result.upRight.y = min(first.upRight.y,first.upRight.y);

	if(result.downLeft.x > result.upRight.x || result.downLeft.y > result.upRight.y) {
		result.upRight = make_pair(0,0);
		result.downLeft = make_pair(0,0);
	}

	return result;
}

long long area(rectangle myRectangle) {
	return ((myRectangle.upRight.x - myRectangle.downLeft.x) * (myRectangle.upRight.y - myRectangle.downLeft.y));
}

long long perimeter(rectangle myRectangle) {
	return 2 * ((myRectangle.upRight.x - myRectangle.downLeft.x) + (myRectangle.upRight.y - myRectangle.downLeft.y));
}