Cod sursa(job #927123)

Utilizator DEYDEY2Tudorica Andrei DEYDEY2 Data 25 martie 2013 16:35:21
Problema Reuniune Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
using namespace std;
typedef struct  {long long x1,y1,x2,y2;} drept;
drept d[3];
long long a,p;

long long arie(drept a)
{
    return (a.x2-a.x1)*(a.y2-a.y1);
}
long long perimetru(drept a)
{
    return 2*(a.x2-a.x1+a.y2-a.y1);
}

drept reuniune(drept a, drept b)
{
    drept aux;
     aux.x1=max(a.x1,b.x1);
     aux.y1=max(a.y1,b.y1);
     aux.x2=min(a.x2,b.x2);
     aux.y2=min(a.y2,b.y2);
     if (aux.x1>aux.x2 || aux.y1>aux.y2)
     aux.x1=aux.x2=aux.y1=aux.y2=0;
   return aux;
}

int main()
{
    ifstream f("reuniune.in");
    ofstream g("reuniune.out");
    for (int i=0; i<3; ++i) f>>d[i].x1>>d[i].y1>>d[i].x2>>d[i].y2;
    a=arie(d[0])+arie(d[1])+arie(d[2]);
    a-=arie(reuniune(d[0],d[1]))-arie(reuniune(d[0],d[2]))-arie(reuniune(d[1],d[2]));
    a+=arie(reuniune(reuniune(d[0],d[1]),d[2]));
    p=perimetru(d[0])+perimetru(d[1])+perimetru(d[2]);
    p-=perimetru(reuniune(d[0],d[1]))-perimetru(reuniune(d[0],d[2]))-perimetru(reuniune(d[1],d[2]));
    p+=perimetru(reuniune(reuniune(d[0],d[1]),d[2]));
    g<<a<<" "<<p;
  return 0;
}