Cod sursa(job #476906)

Utilizator andrei.dAndrei Diaconeasa andrei.d Data 12 august 2010 17:50:50
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <cstdio>
#include <algorithm>

using namespace std;

#define file_in "reuniune.in"
#define file_out "reuniune.out"

struct drept
{
	long long x1,x2,y1,y2;
}
A,B,C,AxB,AxC,BxC,AxBxC;



void citire()
{
	freopen(file_in,"r",stdin);
	freopen(file_out,"w",stdout);
	
    scanf("%lld %lld %lld %lld", &A.x1,&A.y1,&A.x2,&A.y2); 	
    scanf("%lld %lld %lld %lld", &B.x1,&B.y1,&B.x2,&B.y2); 	
    scanf("%lld %lld %lld %lld", &C.x1,&C.y1,&C.x2,&C.y2); 	
	
}


long long aria(drept a)
{
	return abs(a.x2-a.x1)*abs(a.y2-a.y1);
}

long long perimetru(drept a)
{
	return 2*(abs(a.x2-a.x1)+abs(a.y2-a.y1));
}

drept intersectie(drept a, drept b)
{
	drept x;
	
	x.x1=max(a.x1,b.x1);
	x.y1=max(a.y1,b.y1);
	
	x.x2=min(a.x2,b.x2);
	x.y2=min(a.y2,b.y2);
	
	return x;
}

void solve()
{
	if (A.x1>A.x2) swap(A.x1,A.x2);
	if (A.y1>A.y2) swap(A.y1,A.y2);
	if (B.x1>B.x2) swap(B.x1,B.x2);
	if (B.y1>B.y2) swap(B.y1,B.y2);
	if (C.x1>C.x2) swap(C.x1,C.x2);
	if (C.y1>C.y2) swap(C.y1,C.y2);

	AxB=intersectie(A,B);
	AxC=intersectie(A,C);
	BxC=intersectie(B,C);
	AxBxC=intersectie(AxB,C);
	
	
	//printf("%lld %lld %lld %lld %lld %lld %lld\n", aria(A),aria(B),aria(C),aria(AxB),aria(AxC),aria(BxC),aria(AxBxC));
	printf("%lld ", aria(A)+aria(B)+aria(C)-aria(AxB)-aria(AxC)-aria(BxC)+aria(AxBxC));
	printf("%lld ", perimetru(A)+perimetru(B)+perimetru(C)-perimetru(AxB)-perimetru(AxC)-perimetru(BxC)+perimetru(AxBxC));
}



int main()
{
	citire();
	solve();
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
	
}