Cod sursa(job #448301)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 3 mai 2010 13:51:49
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.7 kb
#include<cstdio>
#define LL long long
#define minn(a,b) ((a<b)?a:b)
bool trei=true,ar=false;
LL arie123,per123, rezarie, rezper;
int x11,x12,y11,y12,x21,x22,y21,y22,x31,x32,y31,y32;
int Px1,Px2,Py1,Py2;
int x1,x2,y1,y2;
bool funct(int x11,int x12,int x21,int x22, int &x1, int &x2)
{
	if (x11<=x21)
		if (x21<=x12)
		{
			x1=x21;
			x2=minn(x22,x12);
			return true;
		}
	return false;
}
void calcul(int x1, int x2, int y1, int y2, LL &arie12, LL &per12)
{
	arie12=(LL)(x2-x1)*(y2-y1);
	per12=(LL)(x2-x1+y2-y1)<<1;
}
void verific(int x11, int x12, int x21, int x22, int y11, int y12, int y21, int y22, LL &arie12, LL &per12, int x, int xx, int y, int yy)
{
	if (funct(x11,x12,x21,x22,x1,x2))
	{
		if (funct(y11,y12,y21,y22,y1,y2))
			calcul(x1,x2,y1,y2,arie12,per12);
		else
			if (funct(y21,y22,y11,y12,y1,y2))
				calcul(x1,x2,y1,y2,arie12,per12);
			else
				trei=false;
	}
	else
		if (funct(x21,x22,x11,x12,x1,x2))
		{
			if (funct(y11,y12,y21,y22,y1,y2))
				calcul(x1,x2,y1,y2,arie12,per12);
			else
				if (funct(y21,y22,y11,y12,y1,y2))
					calcul(x1,x2,y1,y2,arie12,per12);
				else
					trei=false;
		}
		else 
			trei= false;
	if (!trei|| ar)
		return ;
	if (funct(x1,x2,x,xx,Px1,Px2))
	{
		if (funct(y1,y2,y,yy,Py1,Py2))
		{
			calcul(Px1,Px2,Py1,Py2,arie123,per123);
			ar=true;
		}
		else
			if (funct(y,yy,y1,y2,Py1,Py2))
			{
				calcul(Px1,Px2,Py1,Py2,arie123,per123);
				ar=true;
			}
			else
				trei=false;
	}
	else
		if (funct(x,xx,x1,x2,Px1,Px2))
		{
			if (funct(y1,y2,y,yy,Py1,Py2))
			{
				calcul(Px1,Px2,Py1,Py2,arie123,per123);
				ar=true;
			}
			else
				if (funct(y,yy,y1,y2,Py1,Py2))
				{
					ar=true;
					calcul(Px1,Px2,Py1,Py2,arie123,per123);
				}
				else
					trei=false;
		}
		else 
			trei= false;
	
}
int main()
{
	LL aria1=0,aria2=0,aria3=0,arie12=0,arie13=0,arie23=0,per1=0,per2=0,per3=0,per12=0,per13=0,per23=0;

	freopen("reuniune.in","r", stdin);
	freopen("reuniune.out","w",stdout);
	scanf("%d%d%d%d",&x11,&y11,&x12,&y12);
	aria1=(LL)(x12-x11)*(y12-y11);
	per1=(LL)(x12-x11+y12-y11)<<1;
	
	scanf("%d%d%d%d",&x21,&y21,&x22,&y22);
	aria2=(LL)(x22-x21)*(y22-y21);
	per2=(LL)(x22-x21+y22-y21)<<1;
		
	scanf("%d%d%d%d",&x31,&y31,&x32,&y32);
	aria3=(LL)(x32-x31)*(y32-y31);
	per3=(LL)(x32-x31+y32-y31)<<1;
	
	verific(x11,x12,x21,x22,y11,y12,y21,y22, arie12, per12, x31, x32, y31, y32);
	verific(x11,x12,x31,x32,y11,y12,y31,y32, arie13, per13, x21, x22, y21, y22);
	verific(x21,x22,x31,x32,y21,y22,y31,y32, arie23, per23, x11, x12, y11, y12);
	
	rezarie=aria1+aria2+aria3-arie12-arie13-arie23+arie123;
	rezper=per1+per2+per3-per12-per13-per23+per123;
	printf("%lld %lld",rezarie,rezper);
	return 0;

}