Cod sursa(job #559309)

Utilizator cristiprgPrigoana Cristian cristiprg Data 17 martie 2011 19:29:28
Problema Reuniune Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.52 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 (max(A.x0, B.x0)  <  min(A.x1, B.x1))   ? dreptunghi(max(A.x0, B.x0), max(A.y0, B.y0), min(A.x1, B.x1), min(A.y1, B.y1)) : dreptunghi(min(A.x1, B.x1),min(A.y1, B.y1),max(A.x0, B.x0) , max(A.y0, B.y0) ) ;
}

ll Arie(dreptunghi A)
{
	return (A.x1-A.x0)*(A.y1-A.y0);
}

ll Per(dreptunghi A)
{
	return 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);
	dreptunghi ba = intersectie(C, A);
	printf("%lld %lld %lld %lld\nArie %lld\nPer %lld", ba.x0, ba.y0, ba.x1, ba.y1, Arie(ba), Per(ba));
	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;
}