Cod sursa(job #783080)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 2 septembrie 2012 08:29:30
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.94 kb
#include <cstdio>
#include <algorithm>

using namespace std;

const int oo = 1000000005;

struct Rectangle {
    int x1, y1, x2, y2;
    Rectangle(int _x1, int _y1, int _x2, int _y2) {
        x1 = _x1, y1 = _y1, x2 = _y2, y2 = _y2;
    }
    Rectangle() {
        x1 = y1 = x2 = y2 = 0;
    }
};

Rectangle Null(-oo, -oo, oo, oo);
Rectangle R[3];

inline int IntersectOX(Rectangle R1, Rectangle R2, Rectangle R3) {
    int X1 = max(R3.x1, max(R1.x1, R2.x1)), X2 = min(R3.x2, min(R1.x2, R2.x2));
    if (X1 >= X2)
        return 0;
    return X2-X1;
}

inline int IntersectOY(Rectangle R1, Rectangle R2, Rectangle R3) {
    int Y1 = max(R3.y1, max(R1.y1, R2.y1)), Y2 = min(R3.y2, min(R1.y2, R2.y2));
    if (Y1 >= Y2)
        return 0;
    return Y2-Y1;
}

inline long long IntersectS(Rectangle R1, Rectangle R2, Rectangle R3 = Null) {
    return 1LL*IntersectOX(R1, R2, R3)*IntersectOY(R1, R2, R3);
}

inline long long IntersectP(Rectangle R1, Rectangle R2, Rectangle R3 = Null) {
    int X = IntersectOX(R1, R2, R3);
    int Y = IntersectOY(R1, R2, R3);
    if (!X || !Y)
        return 0;
    return 1LL*2*X+1LL*2*Y;
}

inline void ReadRectangle(Rectangle &r) {
    scanf("%d %d %d %d", &r.x1, &r.y1, &r.x2, &r.y2);
}

void Read() {
    freopen("reuniune.in", "r", stdin);
    for (int i = 0; i < 3; ++i)
        ReadRectangle(R[i]);
}

void Print() {
    freopen("reuniune.out", "w", stdout);
    printf("%lld ", IntersectS(R[0], R[0])+IntersectS(R[1], R[1])+IntersectS(R[2], R[2])
                   -IntersectS(R[0], R[1])-IntersectS(R[0], R[2])-IntersectS(R[1], R[2])
                   +IntersectS(R[0], R[1], R[2]));
    printf("%lld\n", IntersectP(R[0], R[0])+IntersectP(R[1], R[1])+IntersectP(R[2], R[2])
                   -IntersectP(R[0], R[1])-IntersectP(R[0], R[2])-IntersectP(R[1], R[2])
                   +IntersectP(R[0], R[1], R[2]));
}

int main() {
    Read();
    Print();
    return 0;
}