Cod sursa(job #1224372)

Utilizator xtreme77Patrick Sava xtreme77 Data 30 august 2014 18:53:59
Problema Reuniune Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <fstream>

const char IN [ ] = "reuniune.in" ;
const char OUT [ ] = "reuniune.out" ;

using namespace std;

ifstream fin ( IN ) ;
ofstream fout ( OUT ) ;

struct rectangle {
    int x1 , x2 ;
    int y1 , y2 ;
    void set ( int val )
    {
        x1 = x2 = val ;
        y1 = y2 = val ;
    }
};

rectangle d1 , d2 , d3 ;

rectangle inter ( rectangle a , rectangle b )
{
    rectangle sol ;
    sol.x1 = max ( a.x1 , b.x1 ) ;
    sol.x2 = min ( a.x2 , b.x2 ) ;
    sol.y1 = max ( a.y1 , b.y1 ) ;
    sol.y2 = min ( a.y2 , b.y2 ) ;
    if ( sol.x1 > sol.x2 or sol.y1 > sol.y2 )
        sol.set ( 0 ) ;
    return sol ;
}

long long arie ( rectangle a )
{
    return 1LL * ( a.x2 - a.x1 ) * ( a.y2 - a.y1 ) ;
}

long long perim ( rectangle a )
{
    return ( ( a.x2 - a.x1 ) << 1LL ) + ( ( a.y2 - a.y1 ) << 1LL ) ;
}

void afis ( rectangle unu_doi , rectangle unu_trei , rectangle doi_trei , rectangle unu_doi_trei )
{
    fout << arie ( d1 ) + arie ( d2 ) + arie ( d3 ) - arie ( unu_doi ) - arie ( doi_trei ) - arie ( unu_trei ) + arie ( unu_doi_trei ) << ' ' ;
    fout << perim ( d1 ) + perim ( d2 ) + perim ( d3 ) - perim ( unu_doi ) - perim ( doi_trei ) - perim ( unu_trei ) + perim ( unu_doi_trei ) << '\n' ;
}

int main( )
{
    fin >> d1.x1 >> d1.y1 >> d1.x2 >> d1.y2 ;
    fin >> d2.x1 >> d2.y1 >> d2.x2 >> d2.y2 ;
    fin >> d3.x1 >> d3.y1 >> d3.x2 >> d3.y2 ;
    rectangle unu_doi = inter ( d1 , d2 ) ;
    rectangle unu_trei = inter( d1 , d3 ) ;
    rectangle doi_trei = inter ( d2 , d3 ) ;
    rectangle unu_doi_trei = inter ( unu_doi , d3 ) ;
    afis ( unu_doi , unu_trei , doi_trei , unu_doi_trei ) ;
    return 0;
}