Cod sursa(job #559335)

Utilizator cristiprgPrigoana Cristian cristiprg Data 17 martie 2011 19:38:53
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.33 kb
#include <cstdio>
#define ll long long
inline ll max(const ll &a, const ll &b)
{
	return a>b?a:b;
}

inline ll min(const ll &a, const ll &b)
{
	return a<b?a:b;
}

inline ll abs(const ll &a)
{
	return a>0?a:-a;
}

struct dreptunghi
{
	ll x0, y0, x1, y1;

	dreptunghi(ll x, ll y, ll z, ll t)
	{
		x0 = x;
		y0 = y;
		x1 = z;
		y1 = t;
	}
	
	dreptunghi()
	{
		x0 = -1;
		y0 = -1;
	}
};

dreptunghi A, B, C;

dreptunghi intersectie(dreptunghi A, dreptunghi B)
{
	return  dreptunghi(max(A.x0, B.x0), max(A.y0, B.y0), min(A.x1, B.x1), min(A.y1, B.y1)) ;
	
}

ll Arie(dreptunghi A)
{
	return (A.x0 > A.x1 || A.y0 > A.y1)?0:(A.x1-A.x0)*(A.y1-A.y0);
}

ll Per(dreptunghi A)
{
	return (A.x0 > A.x1 || A.y0 > A.y1)?0:2 * ((A.x1-A.x0) + (A.y1-A.y0));
}

int main()
{
	FILE *f = fopen("reuniune.in", "r");
	fscanf(f, "%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld", &A.x0, &A.y0, &A.x1, &A.y1, &B.x0, &B.y0, &B.x1, &B.y1, &C.x0, &C.y0, &C.x1, &C.y1);
	fclose(f);
	
	ll Ar = Arie(A) + Arie(B) + Arie(C) - Arie(intersectie(A, B)) - Arie(intersectie(B, C)) - Arie(intersectie(A, C)) + Arie(intersectie(intersectie(A, B), C));
	ll P = Per(A) + Per(B) + Per(C) - Per(intersectie(A, B)) - Per(intersectie(B, C)) - Per(intersectie(A, C)) + Per(intersectie(intersectie(A, B), C));
	
	f = fopen("reuniune.out", "w");
	fprintf(f, "%lld %lld\n", Ar, P);
	fclose(f);
	
	return 0;
}