Cod sursa(job #880906)

Utilizator Theorytheo .c Theory Data 17 februarie 2013 15:13:26
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include<fstream>

using namespace std;

#define ll long long

ifstream fin("reuniune.in");
ofstream fout("reuniune.out");

struct Rectangle {
    ll x1, y1, x2, y2;

} v[4];

void Read() {

    for(int i = 1; i <= 3; i++)
        fin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
}

ll Arie(Rectangle R){

    return (R.x2 - R.x1) * (R.y2 - R.y1);
}

ll Perimetru(Rectangle R){

    return (R.x2 - R.x1) * 2 +  (R.y2 - R.y1) * 2;
}

Rectangle Intersection(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.y1 = C.x2 = C.y2 = 0;
        return C;
}

int main() {

    Read();

    ll A = 0, P = 0;
    A = Arie(v[1]) + Arie(v[2]) + Arie(v[3]) - Arie(Intersection(v[1],v[2])) - Arie(Intersection(v[2],v[3])) - Arie(Intersection(v[1],v[3]));

    A += Arie(Intersection(v[1], Intersection(v[2], v[3])));

    P = Perimetru(v[1]) + Perimetru(v[2]) + Perimetru(v[3]) - Perimetru(Intersection(v[1],v[2]))
    -Perimetru(Intersection(v[2],v[3]))- Perimetru(Intersection(v[1],v[3]));

    P += Perimetru(Intersection(v[1], Intersection(v[2], v[3])));

    fout << A << " " << P ;

    return 0;
}