Cod sursa(job #1226394)

Utilizator isav_costinVlad Costin Andrei isav_costin Data 5 septembrie 2014 13:04:07
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <stdio.h>
#include <algorithm>
using namespace std;

struct dreptunghi
{
    int x0, y0, x1, y1;
};

long long arie( dreptunghi d )
{
    return((long long)d.x1-d.x0)*(d.y1-d.y0);
}

long long perimetru ( dreptunghi d )
{
    return 2LL*((d.x1-d.x0)+(d.y1-d.y0));
}

dreptunghi intersectie( dreptunghi d1, dreptunghi d2 )
{
    dreptunghi d12;
    d12.x0=max(d1.x0,d2.x0);
    d12.x1=min(d1.x1,d2.x1);
    d12.y0=max(d1.y0,d2.y0);
    d12.y1=min(d1.y1,d2.y1);
    if( (d12.x0>d12.x1)||(d12.y0>d12.y1) )
    d12.x0=d12.x1=d12.y0=d12.y1;
    return d12;
}

int main()
{
    freopen( "reuniune.in", "r", stdin );
    freopen( "reuniune.out", "w", stdout );
    int a, b, c, d;
    long long ar, per;
    dreptunghi d1, d2, d3;
    scanf( "%d%d%d%d", &a, &b, &c, &d ), d1.x0=a, d1.y0=b, d1.x1=c, d1.y1=d;
    scanf( "%d%d%d%d", &a, &b, &c, &d ), d2.x0=a, d2.y0=b, d2.x1=c, d2.y1=d;
    scanf( "%d%d%d%d", &a, &b, &c, &d ), d3.x0=a, d3.y0=b, d3.x1=c, d3.y1=d;
    dreptunghi d12, d13, d23, d123;
    d12=intersectie(d1,d2);
    d23=intersectie(d2,d3);
    d13=intersectie(d1,d3);
    d123=intersectie(d12,d3);
    ar=arie(d1)+arie(d2)+arie(d3)-arie(d12)-arie(d13)-arie(d23)+arie(d123);
    per=perimetru(d1)+perimetru(d2)+perimetru(d3)-perimetru(d12)-perimetru(d13)-perimetru(d23)+perimetru(d123);
    printf( "%lld %lld\n", ar, per );
    return 0;
}