Cod sursa(job #555263)

Utilizator R.A.RFMI Romila Remus Arthur R.A.R Data 15 martie 2011 13:08:37
Problema Reuniune Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <fstream>

using namespace std;

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

inline int _max(long double a,long double b){if(a>b)return a;return b;}
inline int _min(long double a,long double b){if(a<b)return a;return b;}

struct Dreptunghi{double x1,y1,x2,y2;}D1,D2,D3;

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

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

Dreptunghi reun(Dreptunghi D1,Dreptunghi D2)
{
    Dreptunghi 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 double 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;
    //A1 +A2+A3-A12-A13-A23+A123
    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;
}