Cod sursa(job #357886)

Utilizator funkydvdIancu David Traian funkydvd Data 20 octombrie 2009 22:43:38
Problema Reuniune Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.68 kb
#include<fstream>
using namespace std;
ifstream f1 ("reuniune.in");
ofstream f2 ("reuniune.out");
long long x0,y0,x1,y1,xx0,yy0,xx1,yy1,xxx0,yyy0,xxx1,yyy1,s1,s2,s3,p1,p2,p3;
long long reun1,reun2,reun3,reun4;
long long pe1,pe2,pe3,pe4;
long long c1x,c1y,c2x,c2y;
int main()
{

f1>>x0>>y0>>x1>>y1>>xx0>>yy0>>xx1>>yy1>>xxx0>>yyy0>>xxx1>>yyy1;
s1=(x1-x0)*(y1-y0);
s2=(xx1-xx0)*(yy1-yy0);
s3=(xxx1-xxx0)*(yyy1-yyy0);
p1=((x1-x0)+(y1-y0))*2;
p2=((xx1-xx0)+(yy1-yy0))*2;
p3=((xxx1-xxx0)+(yyy1-yyy0))*2;
if ( y0>=yy1 || x0>=xx1 || y1<=yy0 || x1<=xx0) reun1=0;
 else
 {
    if (x0>xx0 && y0>yy0) {c1x=x0; c1y=y0;}
    if (x0>xx0 && y0<yy0) {c1x=x0; c1y=yy0;}
    if (x0<xx0 && y0>yy0) {c1x=xx0; c1y=y0;}
    if (x0<xx0 && y0<yy0) {c1x=xx0; c1y=yy0;}
    if (x1>xx1 && y1>yy1) {c2x=xx1; c2y=yy1;}
    if (x1>xx1 && y0<yy1) {c2x=xx1; c2y=y1;}
    if (x1<xx1 && y0>yy1) {c2x=x1; c2y=yy1;}
    if (x1<xx1 && y0<yy1) {c2x=x1; c2y=y1;}
 reun1=(c2x-c1x)*(c2y-c1y);
 pe1=((c2x-c1x)+(c2y-c1y))*2;
 }
 if ( yy0>=yyy1 || xx0>=xxx1 || yy1<=yyy0 || xx1<=xxx0)  {reun2=0;}
 else
 {
    if (xx0>xxx0 && yy0>yyy0) {c1x=xx0; c1y=yy0;}
    if (xx0>xxx0 && yy0<yyy0) {c1x=xx0; c1y=yyy0; }
    if (xx0<xxx0 && yy0>yyy0) {c1x=xxx0; c1y=yy0; }
    if (xx0<xxx0 && yy0<yyy0) {c1x=xxx0; c1y=yyy0; }
    if (xx1>xxx1 && yy1>yyy1) {c2x=xxx1; c2y=yyy1;}
    if (xx1>xxx1 && yy1<yyy1) {c2x=xxx1; c2y=yy1;}
    if (xx1<xxx1 && yy1>yyy1) {c2x=xx1; c2y=yyy1;}
    if (xx1<xxx1 && yy1<yyy1) {c2x=xx1; c2y=yy1; }
 reun2=(c2x-c1x)*(c2y-c1y);
  pe2=((c2x-c1x)+(c2y-c1y))*2;
 }
 if ( yyy0>=y1 || xxx0>=x1 || yyy1<=y0 || xxx1<=x0)  {reun3=0;}
 else
 {
    if (xxx0>x0 && yyy0>y0) {c1x=xxx0; c1y=yyy0; }
    if (xxx0>x0 && yyy0<y0) {c1x=xxx0; c1y=y0; }
    if (xxx0<x0 && yyy0>y0) {c1x=x0; c1y=yyy0; }
    if (xxx0<x0 && yyy0<y0) {c1x=x0; c1y=y0; }
    if (xxx1>x1 && yyy1>y1) {c2x=x1; c2y=y1; }
    if (xxx1>x1 && yyy1<y1) {c2x=x1; c2y=yyy1; }
    if (xxx1<x1 && yyy1>y1) {c2x=xxx1; c2y=y1; }
    if (xxx1<x1 && yyy1<y1) {c2x=xxx1; c2y=yyy1;} 
 reun3=(c2x-c1x)*(c2y-c1y);
  pe3=((c2x-c1x)+(c2y-c1y))*2;
 }
 x0=c1x; x1=c2x; y0=c1y; y1=c2y;
 if ( y0>=yy1 || x0>=xx1 || y1<=yy0 || x1<=xx0) reun4=0;
 else
 {
    if (x0>xx0 && y0>yy0) {c1x=x0; c1y=y0;}
    if (x0>xx0 && y0<yy0) {c1x=x0; c1y=yy0;}
    if (x0<xx0 && y0>yy0) {c1x=xx0; c1y=y0;}
    if (x0<xx0 && y0<yy0) {c1x=xx0; c1y=yy0;}
    if (x1>xx1 && y1>yy1) {c2x=xx1; c2y=yy1;}
    if (x1>xx1 && y0<yy1) {c2x=xx1; c2y=y1;}
    if (x1<xx1 && y0>yy1) {c2x=x1; c2y=yy1;}
    if (x1<xx1 && y0<yy1) {c2x=x1; c2y=y1;}
 reun4=(c2x-c1x)*(c2y-c1y);
  pe4=((c2x-c1x)+(c2y-c1y))*2;
 }
 f2<<s1+s2+s3-reun1-reun2-reun3+reun4<<" ";
 f2<<p1+p2+p3-pe1-pe2-pe3+pe4;
return 0;
}