Cod sursa(job #1842136)

Utilizator robx12lnLinca Robert robx12ln Data 6 ianuarie 2017 15:48:00
Problema Reuniune Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.81 kb
#include<fstream>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
long long aria, perimetru;
struct dreptunghi{
    int xmin;
    int ymin;
    int xmax;
    int ymax;
} a, b, c, p, d;
dreptunghi intersect( dreptunghi x, dreptunghi y ){
    dreptunghi z;
    z.xmin = max( x.xmin, y.xmin );
    z.ymin = max( x.ymin, y.ymin );
    z.xmax = min( x.xmax, y.xmax );
    z.ymax = min( x.ymax, y.ymax );
    return z;
}
int vf( dreptunghi n, int x, int y ){
    if( n.xmin <= x && x <= n.xmax && n.ymin <= y && y <= n.ymax ){
        return 1;
    }
    return 0;
}
int ok( dreptunghi x, dreptunghi y ){
    if( vf( x, y.xmin, y.ymin ) == 1 || vf( x, y.xmin, y.ymax ) == 1 || vf( x, y.xmax, y.ymin ) == 1 || vf( x, y.xmax, y.ymax ) == 1 ){
        return 1;
    }
    return 0;
}
long long A( dreptunghi n ){
    return 1LL * ( n.ymax - n.ymin ) * ( n.xmax - n.xmin );
}
long long P( dreptunghi n ){
    return 2LL * ( ( n.ymax - n.ymin ) + ( n.xmax - n.xmin ) );
}
int main(){
    fin >> a.xmin >> a.ymin >> a.xmax >> a.ymax;
    fin >> b.xmin >> b.ymin >> b.xmax >> b.ymax;
    fin >> c.xmin >> c.ymin >> c.xmax >> c.ymax;
    aria = A( a ) + A( b ) + A( c );
    perimetru = P( a ) + P( b ) + P( c );
    if( ok( a, b ) == 1 ){
        p = intersect( a, b );
        aria -= A( p );
        perimetru -= P( p );
    }
    if( ok( a, c ) == 1 ){
        p = intersect( a, c );
        aria -= A( p );
        perimetru -= P( p );
    }
    if( ok( b, c ) == 1 ){
        p = intersect( b, c );
        aria -= A( p );
        perimetru -= P( p );
    }
    d = intersect( b, c );;
    if( ok( a, d ) == 1 ){
        p = intersect( a, d );
        aria += A( p );
        perimetru += P( p );
    }
    fout << aria << " " << perimetru;
    return 0;
}