Cod sursa(job #1032125)

Utilizator george_stelianChichirim George george_stelian Data 15 noiembrie 2013 18:56:43
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct dreptunghi
{
    long long int ax,ay,bx,by;
};

dreptunghi a,b,c;

inline dreptunghi intersect(dreptunghi x,dreptunghi y)
{
    dreptunghi sol;
    sol.ax=max(x.ax,y.ax);
    sol.ay=max(x.ay,y.ay);
    sol.bx=min(x.bx,y.bx);
    sol.by=min(x.by,y.by);
    if(sol.ax>sol.bx || sol.ay>sol.by) sol.ax=sol.ay=sol.bx=sol.by=0;
    return sol;
}

inline long long sup(dreptunghi x)
{
    return (x.bx-x.ax)*(x.by-x.ay);
}

inline long long per(dreptunghi x)
{
    return (x.bx-x.ax+x.by-x.ay)*2;
}

int main()
{
    freopen("reuniune.in", "r", stdin);
    freopen("reuniune.out", "w", stdout);
    scanf("%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld%lld",&a.ax,&a.ay,&a.bx,&a.by,&b.ax,&b.ay,&b.bx,&b.by,&c.ax,&c.ay,&c.bx,&c.by);
    printf("%lld ",sup(a)+sup(b)+sup(c)-sup(intersect(a,b))-sup(intersect(b,c))-sup(intersect(a,c))+sup(intersect(intersect(a,b),c)));
    printf("%lld",per(a)+per(b)+per(c)-per(intersect(a,b))-per(intersect(b,c))-per(intersect(a,c))+per(intersect(intersect(a,b),c)));
    fclose(stdin);fclose(stdout);
    return 0;
}