Cod sursa(job #1932322)

Utilizator 1475369147896537415369Andrei Udriste 1475369147896537415369 Data 19 martie 2017 17:43:51
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.84 kb
#include <cstdio>
#include <algorithm>
using namespace std;

struct rectangle{
    long long leftBottomX, leftBottomY;
    long long rightTopX, rightTopY;

    rectangle(){
        leftBottomX = 0; leftBottomY = 0;
        rightTopX = 0; rightTopY = 0;
    }
    rectangle(long long x0, long long y0, long long x1, long long y1){
        leftBottomX = x0; leftBottomY = y0;
        rightTopX = x1; rightTopY = y1;
    }
};
inline rectangle Intersection(const rectangle &R1, const rectangle &R2){

    long long x0, y0, x1, y1;

    x0 = max(R1.leftBottomX, R2.leftBottomX);
    y0 = max(R1.leftBottomY, R2.leftBottomY);
    x1 = min(R1.rightTopX, R2.rightTopX);
    y1 = min(R1.rightTopY, R2.rightTopY);

    return (x0 > x1 || y0 > y1) ? rectangle() : rectangle(x0, y0, x1, y1);
}
inline long long Area(const rectangle &R){
    return ((R.rightTopY - R.leftBottomY) * (R.rightTopX - R.leftBottomX));
}
inline long long Edge(const rectangle &R){
    return (((R.rightTopY - R.leftBottomY) + (R.rightTopX - R.leftBottomX)) * 2);
}

int main(){

    long long x0, y0, x1, y1, AreaABC, EdgeABC;
    rectangle A, B, C, AC, AB, CB, ABC;

    freopen("reuniune.in", "r", stdin);
    freopen("reuniune.out", "w", stdout);

    scanf("%lld %lld %lld %lld", &x0, &y0, &x1, &y1); A = rectangle(x0, y0, x1, y1);
    scanf("%lld %lld %lld %lld", &x0, &y0, &x1, &y1); B = rectangle(x0, y0, x1, y1);
    scanf("%lld %lld %lld %lld", &x0, &y0, &x1, &y1); C = rectangle(x0, y0, x1, y1);

    AC = Intersection(A, C);
    AB = Intersection(A, B);
    CB = Intersection(C, B);
    ABC = Intersection(AC, B);

    AreaABC = Area(A) + Area(B) + Area(C) - Area(AC) - Area(AB) - Area(CB) + Area(ABC);
    EdgeABC = Edge(A) + Edge(B) + Edge(C) - Edge(AC) - Edge(AB) - Edge(CB) + Edge(ABC);

    printf("%lld %lld", AreaABC, EdgeABC);

    return 0;
}