Cod sursa(job #531740)

Utilizator feelshiftFeelshift feelshift Data 10 februarie 2011 10:47:24
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.07 kb
// http://infoarena.ro/problema/reuniune
#include <fstream>
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 one,rectangle two);
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(first,third))
         - area(intersection(second,third))
         + area( intersection (intersection(first,second),third) );

	out << " ";

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

	return (0);
}

rectangle intersection(rectangle one,rectangle two) {
	rectangle result;

	result.downLeft.x = max(one.downLeft.x,two.downLeft.x);
	result.downLeft.y = max(one.downLeft.y,two.downLeft.y);

	result.upRight.x = min(one.upRight.x,two.upRight.x);
	result.upRight.y = min(one.upRight.y,two.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));
}