Cod sursa(job #991069)

Utilizator sleepaholicNeculaescu Theodor sleepaholic Data 29 august 2013 17:22:46
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.94 kb
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

const LL oo = 10000000000LL;

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

    Rectangle() {}

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

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

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

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

inline LL IntersectS(Rectangle R1, Rectangle R2 = Null, Rectangle R3 = Null) {
    LL width = IntersectOX(R1, R2, R3), height = IntersectOY(R1, R2, R3);
    if (width < 0 || height < 0)
        return 0;
    return width * height;
}

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

inline void ReadRectangle(Rectangle &r) {
    scanf("%lld %lld %lld %lld", &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]) + IntersectS(R[1]) + IntersectS(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]) + IntersectP(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;
}