Cod sursa(job #379503)

Utilizator DraStiKDragos Oprica DraStiK Data 1 ianuarie 2010 23:50:47
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.59 kb
#include <algorithm>
using namespace std;

struct punct {long long x,y;};
struct drept {punct ss,dj;} a[10];

void read ()
{
    int i;

    for (i=1; i<=3; ++i)
        scanf ("%lld%lld%lld%lld",&a[i].ss.x,&a[i].dj.y,&a[i].dj.x,&a[i].ss.y);
}

int intersectie (drept a,drept b)
{
    return a.dj.x>=b.ss.x && b.dj.x>=a.ss.x && a.dj.y<=b.ss.y && b.dj.y<=a.ss.y;
}

punct stanga_sus (drept a,drept b)
{
    punct t;

    t.x=max (a.ss.x,b.ss.x);
    t.y=min (a.ss.y,b.ss.y);
    return t;
}

punct dreapta_jos (drept a,drept b)
{
    punct t;

    t.x=min (a.dj.x,b.dj.x);
    t.y=max (a.dj.y,b.dj.y);
    return t;
}

drept unite (drept a,drept b)
{
    drept t;

    t.ss=stanga_sus (a,b);
    t.dj=dreapta_jos (a,b);
    return t;
}

long long arie (drept a)
{
    return (a.dj.x-a.ss.x)*(a.ss.y-a.dj.y);
}

long long perim (drept a)
{
    return 2*(a.dj.x-a.ss.x+a.ss.y-a.dj.y);
}

void solve ()
{
    long long ar,pr;

    if (intersectie (a[1],a[2]))
        a[4]=unite (a[1],a[2]);
    if (intersectie (a[1],a[3]))
        a[5]=unite (a[1],a[3]);
    if (intersectie (a[2],a[3]))
        a[6]=unite (a[2],a[3]);
    if (intersectie (a[3],a[4]))
        a[7]=unite (a[3],a[4]);
    ar=arie (a[1])+arie (a[2])+arie (a[3])-arie (a[4])-arie (a[5])-arie (a[6])+arie (a[7]);
    pr=perim (a[1])+perim (a[2])+perim (a[3])-perim (a[4])-perim (a[5])-perim (a[6])+perim (a[7]);
    printf ("%lld %lld",ar,pr);
}

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

    read ();
    solve ();

    return 0;
}