Cod sursa(job #1134826)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 6 martie 2014 22:14:54
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.81 kb
#include <iostream>
#include <fstream>

using namespace std;

struct Point
{
    long long x, y;

    Point( const long long _x = 0, const long long _y = 0 ) : x( _x ), y ( _y ) {}

    bool operator <= ( const Point P ) const
    {
        return ( x <= P.x && y <= P.y );
    }

    friend istream& operator >> ( istream &f, Point &P )
    {
        f >> P.x >> P.y;
        return f;
    }
};

struct Rectangle
{
    Point SJ, DS;

    Rectangle( ) { }
    Rectangle( Point A, Point B ) : SJ( A ), DS( B ) { }

    friend istream& operator >> ( istream &f, Rectangle &R )
    {
        f >> R.SJ >> R.DS;
        return f;
    }
};

template <class T>
T abs( T x )
{
    if ( x > 0 )
            return +x;
    else
            return -x;
}

long long Area( Rectangle R )
{
    return static_cast <long long> ( abs( R.SJ.x - R.DS.x ) * abs( R.SJ.y - R.DS.y ) );
}

long long Perm( Rectangle R )
{
    return static_cast <long long> ( 2LL * ( abs( R.SJ.x - R.DS.x ) + abs( R.SJ.y - R.DS.y ) ) );
}

Rectangle I( Rectangle A, Rectangle B )
{
    Rectangle C;

    C.SJ.x = max( A.SJ.x, B.SJ.x );
    C.SJ.y = max( A.SJ.y, B.SJ.y );

    C.DS.x = min( A.DS.x, B.DS.x );
    C.DS.y = min( A.DS.y, B.DS.y );

    if ( C.SJ <= C.DS )
            return C;
    else
            return Rectangle( Point( 0, 0 ), Point( 0, 0 ) );

    return C;
}

int main()
{
    ifstream f("reuniune.in");
    ofstream g("reuniune.out");

    Rectangle A, B, C;

    f >> A >> B >> C;

    g << Area( A ) + Area( B ) + Area( C ) - Area( I( A, B ) ) - Area( I( B, C ) ) - Area( I( A, C ) ) + Area( I( I( A, B ), C ) ) << " ";
    g << Perm( A ) + Perm( B ) + Perm( C ) - Perm( I( A, B ) ) - Perm( I( B, C ) ) - Perm( I( A, C ) ) + Perm( I( I( A, B ), C ) ) << endl;

    return 0;
}