Cod sursa(job #586623)

Utilizator theocmtAxenie Theodor theocmt Data 2 mai 2011 17:20:10
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>

using namespace std;

ifstream in("reuniune.in");
ofstream out("reuniune.out");


inline long long  max(long long a,long long b)
{
	if(a>b)
		return a;
	return b;
}
inline long long  min(long long a,long long b)
{
	if(a<b)
		return a;
	return b;
}

struct Drept
{
	long long x1,y1,x2,y2;
}D1,D2,D3;

long long Arie(Drept D1)
{
    return (D1.x2-D1.x1)*(D1.y2-D1.y1);
}

long long Perm(Drept D1)
{
    return 2*((D1.x2-D1.x1)+(D1.y2-D1.y1));
}

Drept reun(Drept D1,Drept D2)
{
    Drept aux;
    aux.x1= max(D1.x1,D2.x1);
    aux.y1= max(D1.y1,D2.y1);
    aux.x2= min(D1.x2,D2.x2);
    aux.y2= min(D1.y2,D2.y2);
    if(aux.x1>aux.x2||aux.y1>aux.y2)
        aux.x1=aux.y1=aux.x2=aux.y2=0;
    return aux;
}

int main()
{
    long long A,S;
    in>>D1.x1>>D1.y1>>D1.x2>>D1.y2;
    in>>D2.x1>>D2.y1>>D2.x2>>D2.y2;
    in>>D3.x1>>D3.y1>>D3.x2>>D3.y2;
    A = Arie(D1)+Arie(D2)+Arie(D3)-Arie(reun(D1,D2))-Arie(reun(D2,D3))-Arie(reun(D1,D3))+Arie(reun(reun(D1,D2),D3));
    S = Perm(D1)+Perm(D2)+Perm(D3)-Perm(reun(D1,D2))-Perm(reun(D2,D3))-Perm(reun(D1,D3))+Perm(reun(reun(D1,D2),D3));
    out<<A<<' '<<S;
    return 0;
}