Cod sursa(job #1223716)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 28 august 2014 17:34:56
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
#include <cstdio>
#include <cmath>
#include <algorithm>

#define NMAX 4

using namespace std;

struct reun{
    int x1;
    int y1;
    int x2;
    int y2;
};

reun v[NMAX];

inline long long solve(reun a){
    return (1LL) * fabs(a.x2 - a.x1) * fabs(a.y2 - a.y1);
}

inline long long solve2(reun a){
    return (1LL) * (fabs(a.x2 - a.x1) + fabs(a.y2 - a.y1)) * 2;
}

reun intersect(reun a, reun b){
    reun 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.x1 = c.x2 = c.y1 = c.y2 = 0;
        return c;
    }
    return c;
}

int main(){
    freopen("reuniune.in", "r", stdin);
    freopen("reuniune.out", "w", stdout);
    long long Ans = 0, Ans2 = 0;
    for(int i = 1; i <= 3; ++i){
        scanf("%d %d %d %d", &v[i].x1, &v[i].y1, &v[i].x2, &v[i].y2);
        Ans += (1LL) * solve(v[i]);
        Ans2 += (1LL) * solve2(v[i]);
    }
    for(int i = 1; i <= 3; ++i)
        for(int j = i + 1; j <= 3; ++j){
            Ans -= (1LL) * solve(intersect(v[i], v[j]));
            Ans2 -= (1LL) * solve2(intersect(v[i], v[j]));
        }
    Ans += (1LL) * solve(intersect(intersect(v[1], v[2]), v[3]));
    Ans2 += (1LL) * solve2(intersect(intersect(v[1], v[2]), v[3]));
    printf("%lld %lld\n", Ans, Ans2);
    return 0;
}