Cod sursa(job #607966)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 14 august 2011 00:52:13
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.65 kb
#include<fstream.h>
typedef struct
{long long x,y;}punct;
typedef struct
{punct c,d;}Drept;
int i;
long long A,P;
punct a[4],b[4];
Drept r[4],w1,w2,w3,w4;

long long min(long long x,long long y)
{if(x<y)
       return x;
return y;}

long long max(long long x,long long y)
{if(x<y)
       return y;
return x;}

punct SS(Drept r1,Drept r2)
{punct a;
a.x=max(r1.c.x,r2.c.x);
a.y=min(r1.c.y,r2.c.y);
return a;}

punct DJ(Drept r1,Drept r2)
{punct a;
a.x=min(r1.d.x,r2.d.x);
a.y=max(r1.d.y,r2.d.y);
return a;}

long long Aria(punct v,punct w)
{return (w.x-v.x)*(v.y-w.y);}

long long Peri(punct v,punct w)
{return 2*((w.x-v.x)+(v.y-w.y));}

Drept Inter(Drept r1,Drept r2)
{Drept a;
a.c=SS(r1,r2);
a.d=DJ(r1,r2);
return a;}

int intersect(Drept r1,Drept r2)
{return r1.d.x>=r2.c.x&&r1.c.x<=r2.d.x&&r1.d.y<=r2.c.y&&r1.c.y>=r2.d.y;}

int main()
{ifstream f1("reuniune.in");
ofstream f2("reuniune.out");
for(i=1;i<4;i++)
        {f1>>a[i].x>>a[i].y>>b[i].x>>b[i].y;
        r[i].c.x=a[i].x;
        r[i].c.y=b[i].y;
        r[i].d.x=b[i].x;
        r[i].d.y=a[i].y;
        P+=Peri(r[i].c,r[i].d);
        A+=Aria(r[i].c,r[i].d);}
if(intersect(r[1],r[2]))
        {w1=Inter(r[1],r[2]);
        A-=Aria(w1.c,w1.d);
        P-=Peri(w1.c,w1.d);}
if(intersect(r[1],r[3]))
        {w2=Inter(r[1],r[3]);
        A-=Aria(w2.c,w2.d);
        P-=Peri(w2.c,w2.d);}
if(intersect(r[2],r[3]))
        {w3=Inter(r[2],r[3]);
        A-=Aria(w3.c,w3.d);
        P-=Peri(w3.c,w3.d);}
if(intersect(r[1],r[2])&&intersect(w1,r[3]))
        {w4=Inter(w1,r[3]);
        A+=Aria(w4.c,w4.d);
        P+=Peri(w4.c,w4.d);}
f2<<A<<' '<<P;
return 0;}