Cod sursa(job #911215)

Utilizator mihanechitaNechita Mihaela mihanechita Data 11 martie 2013 14:01:48
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
 
using namespace std;
 
ifstream fin("reuniune.in"); ofstream fout("reuniune.out");
 
struct drept
{
    long long x1, x2, y1, y2;
}
d[3];
long long a,p;
 
long long arie(drept a)
{
    return (a.x2 - a.x1) * (a.y2 - a.y1);
}
 
long long per(drept a)
{
    return 2 * (a.x2 - a.x1 + a.y2 - a.y1);
}
 
drept reun(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()
{
    for (int i = 0; i < 3; i++)
        fin >> d[i].x1 >> d[i].y1 >> d[i].x2 >> d[i].y2;
 
    a = arie(d[0]) + arie(d[1]) + arie(d[2]) -
         arie(reun(d[0], d[1])) - arie(reun(d[0], d[2])) - arie(reun(d[1] , d[2])) +
         arie(reun(reun(d[0] , d[1]) , d[2]));
 
    p = per(d[0]) + per(d[1]) + per(d[2]) -
        per(reun(d[0], d[1])) - per(reun(d[0], d[2])) - per(reun(d[1],d[2])) +
        per(reun(reun(d[0], d[1]), d[2]));
 
    fout<<a<<" "<<p;
 
  return(0);
}