Cod sursa(job #944288)

Utilizator superman_01Avramescu Cristian superman_01 Data 27 aprilie 2013 23:39:25
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#include<cstdio>

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define LL long long

FILE *f=fopen("reuniune.in","r");
FILE *g=fopen("reuniune.out","w");

using namespace std;

struct fig
{
    LL x0,y0,x1,y1;
};

fig a,b,c;

LL total_area,total_perimeter;

void Read ( void )
{
        fscanf(f,"%lld%lld%lld%lld",&a.x0,&a.y0,&a.x1,&a.y1);
        fscanf(f,"%lld%lld%lld%lld",&b.x0,&b.y0,&b.x1,&b.y1);
        fscanf(f,"%lld%lld%lld%lld",&c.x0,&c.y0,&c.x1,&c.y1);

    fclose(f);
}
fig Intersection( fig a , fig b )
{
    fig aux;
   aux.x0=max(a.x0,b.x0);
   aux.y0=max(a.y0,b.y0);
   aux.x1=min(a.x1,b.x1);
   aux.y1=min(a.y1,b.y1);
   if(aux.x0 > aux.x1 || aux .y0 > aux .y1 )
   aux.x0=aux.x1=aux.y0=aux.y1=0;
   return aux;
}
inline LL Area( fig a )
{
    return 1LL*(a.x1-a.x0)*(a.y1-a.y0);
}
inline LL Perimeter ( fig a )
{
   return 1LL*2*((a.x1-a.x0)+(a.y1-a.y0));
}

void Solve ( void )
{
  total_area=Area(a)+Area(b)+Area(c)-Area(Intersection(a,b))-Area(Intersection(a,c))-Area(Intersection(b,c))+Area(Intersection(Intersection(a,b),c));
  total_perimeter=Perimeter(a)+Perimeter(b)+Perimeter(c)- Perimeter(Intersection(a,b))-Perimeter(Intersection(a,c))-Perimeter(Intersection(b,c))+Perimeter(Intersection(Intersection(a,c),b));

}
void Write ( void )
{
    fprintf(g,"%lld %lld",total_area,total_perimeter);
    fclose(g);
}
int main ( void )
{
    Read();
    Solve();
    Write ();
    return 0;

}