Cod sursa(job #780700)

Utilizator visanrVisan Radu visanr Data 21 august 2012 00:00:07
Problema Reuniune Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>
#include <algorithm>
using namespace std;

#define ll long long

struct rectangle
{
       ll X1, Y1, X2, Y2;
}v[4];


ll Area(rectangle A)
{
      return ((A.X2 - A.X1) * (A.Y2 - A.Y1));
}

ll Per(rectangle A)
{
      return (2 * (A.X2 - A.X1 + A.Y2 - A.Y1));
}

rectangle Intersect(rectangle A, rectangle B)
{
      rectangle C;
      C.X1 = max(A.X1, B.X1);
      C.X2 = min(A.X2, B.X2);
      C.Y1 = max(A.Y1, B.Y1);
      C.Y2 = min(A.Y2, B.Y2);
      if(C.X1 > C.X2 || C.Y1 > C.Y2) 
              C.X1 = C.X2 = C.Y1 = C.Y2 = 0;
      return C;
}

int main()
{
    ifstream in("reuniune.in");
    ofstream out("reuniune.out");
    ll A, P;
    for(i = 1; i <= 3; i++) 
          in >> v[i].X1 >> v[i].Y1 >> v[i].X2 >> v[i].Y2;
    in.close();
    A = Area(v[1]) + Area(v[2]) + Area(v[3]) - Area(Intersect(v[1], v[2])) - Area(Intersect(v[2], v[3])) - Area(Intersect(v[1], v[3]));
    A += Area(Intersect(v[1], Intersect(v[2], v[3])));
    P = Per(v[1]) + Per(v[2]) + Per(v[3]) - Per(Intersect(v[1], v[2])) - Per(Intersect(v[2], v[3])) - Per(Intersect(v[1], v[3]));
    P += Per(Intersect(v[1], Intersect(v[2], v[3])));
    out << A << " " << P << "\n";
    out.close();
    return 0;
}