Cod sursa(job #493153)

Utilizator ooctavTuchila Octavian ooctav Data 17 octombrie 2010 13:23:36
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.55 kb
#include<cstdio>
const int DRMAX = 10;

int NR = 3;
int x1[DRMAX], y1[DRMAX], x2[DRMAX], y2[DRMAX];
bool NA[DRMAX];
int A, P;

inline int min(int a, int b)
{
	if(a < b)
		return a;
	return b;
}

inline int max(int a, int b)
{
	if(a > b)
		return a;
	return b;
}

void citire()
{
	for(int i = 1 ; i <= 3 ; i++)
		scanf("%lld%lld%lld%lld", &x1[i], &y1[i], &x2[i], &y2[i]);
}

void coord(int c1, int c2)
{
	x1[++NR] = max(x1[c1], x1[c2]);
	y1[NR] = max(y1[c1], y1[c2]);
	x2[NR] = min(x2[c1], x2[c2]);
	y2[NR] = min(y2[c1], y2[c2]);
}

void rezolva()
{
	for(int i = 1 ; i <= 3 ; i++)
	{
		A += (x2[i] - x1[i])*(y2[i] - y1[i]);
		P += 2*((x2[i] - x1[i])+(y2[i] - y1[i]));
	}
	
	coord(1, 2);
	coord(1, 3);
	coord(2, 3);
	
	for(int i = 4 ; i <= 6 ; i++)
		if((x1[i] - x2[i])*(y1[i] - y2[i]) < 0)
			NA[i] = true;
		else if(x1[i] == x2[i] || y1[i] == y2[i]) 
		{
			if(x1[i] == x2[i] && y2[i] - y1[i] > 0)
				P -= 2*(y2[i] - y1[i]);
			else if(y1[i] == y2[i] && x2[i] - x1[i] > 0)
				P -= 2*(x2[i] - x1[i]);
		}
		else
		{
			A -= (x2[i] - x1[i])*(y2[i] - y1[i]);
			P -=2*((x2[i] - x1[i]) + (y2[i] - y1[i]));
		}
	
	if(!NA[4] && !NA[5] && !NA[6])
	{
		coord(4, 5);
		A += (x2[7] - x1[7])*(y2[7] - y1[7]);
		P += 2*((x2[7] - x1[7]) + (y2[7] - y1[7]));
	}
} 

void scrie()
{
	if(NA[4] && NA[5] && NA[6])
	{
		printf("0 0");
		return;
	}
	printf("%d %d", A, P);
}

int main()
{
	freopen("reuniune.in", "r", stdin);
	freopen("reuniune.out", "w", stdout);
	citire();
	rezolva();
	scrie();
	return 0;
}