Cod sursa(job #1360276)

Utilizator gedicaAlpaca Gedit gedica Data 25 februarie 2015 13:27:50
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.38 kb
#include <fstream>
#include <algorithm>

using namespace std;

const int NMAX= 3;

ifstream in( "reuniune.in" );
ofstream out( "reuniune.out" );

struct drp
{
    int x1, y1, x2, y2;

    drp( int xx1= 0, int xx2= 0,int yy1= 0,int yy2= 0 )
    {

        x1= xx1;
        y1= yy1;
        x2= xx2;
        y2= yy2;

    }

};

drp v[NMAX+1], aUb, aUc, bUc, aUbUc;

drp calc_ans( drp a, drp b )
{
    drp ans= drp( 0, 0, 0, 0 );

    ans.x1= max( a.x1, b.x1 );
    ans.y1= max( a.y1, b.y1 );
    ans.x2= min( a.x2, b.x2 );
    ans.y2= min( a.y2, b.y2 );

    if( b.x1 > a.x2 || a.x1 > b.x2 || a.y1 > b.y2 || b.y1 > a.y2 )
    {
        return drp( 0, 0, 0, 0 );
    }

    return ans;
}

long long S( drp a )
{
    return ( long long )( a.x2-a.x1 ) * ( a.y2-a.y1 );
}

long long P( drp a )
{
    return ( long long )( a.x2-a.x1 ) * 2+( long long ) 2 * ( a.y2-a.y1 );

}

int main(  )
{
    for( int i= 1; i<=3; ++i )
    {
        in >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    }

    aUb= calc_ans( v[1], v[2] );

    aUc= calc_ans( v[1], v[3] );

    bUc= calc_ans( v[2], v[3] );

    aUbUc= calc_ans( aUb, v[3] );

    out << S( v[1] ) + S( v[2] ) + S( v[3] ) - S( aUb ) - S( aUc ) - S( bUc ) + S( aUbUc ) << ' ';
    out << P( v[1] ) + P( v[2] ) + P( v[3] ) - P( aUb ) - P( aUc ) - P( bUc ) + P( aUbUc ) << '\n';

    return 0;
}