Cod sursa(job #559280)

Utilizator cristiprgPrigoana Cristian cristiprg Data 17 martie 2011 19:02:01
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <cstdio>

inline int max(const int &a, const int &b)
{
	return a>b?a:b;
}

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

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

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

	dreptunghi(int x, int y, int z, int 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));
}

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

int Per(dreptunghi A)
{
	return 2 * ((A.x1-A.x0) + (A.y1-A.y0));
}

int main()
{
	FILE *f = fopen("reuniune.in", "r");
	fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d%d", &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);
	
	int 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));
	int 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, "%d %d\n", Ar, P);
	fclose(f);
	
	return 0;
}