Cod sursa(job #838650)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 20 decembrie 2012 10:03:23
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std ;
struct brailu
{
    long x1 , x2 , y1 , y2 ;
};
brailu a [ 7 ] , temp1 , temp2 , temp3 , temp4 ;
brailu intersectie ( brailu a , brailu b )
{
    brailu temp ;
    temp . x1 = max ( a . x1 , b . x1 ) ;
    temp . x2 = min ( a . x2 , b . x2 ) ;
    temp . y1 = max ( a . y1 , b . y1 ) ;
    temp . y2 = min ( a . y2 , b . y2 ) ;
    if ( temp . x1 > temp . x2 || temp . y1 > temp . y2 )
        temp . x1 = temp . x2 = temp . y1 = temp . y2 = 0 ;
    return temp ;
}
long long perimetru ( brailu a )
{
    return ( long long ) 2 * ( ( long long ) abs ( a . x2 - a . x1 ) + ( long long ) abs ( a . y2 - a . y1 )  ) ;
}
long long arie ( brailu a )
{
    return ( long long )abs ( a . x2 - a . x1 ) * ( long long ) abs ( a . y2 - a . y1 ) ;
}
int main ( )
{
    freopen ( "reuniune.in" , "r" , stdin ) ;
    freopen ( "reuniune.out" , "w" , stdout ) ;
    scanf ( "%ld %ld %ld %ld\n" , & a [ 1 ] . x1 , & a [ 1 ] . y1 , & a [ 1 ] . x2 , & a [ 1 ] . y2 ) ;
    scanf ( "%ld %ld %ld %ld\n" , & a [ 2 ] . x1 , & a [ 2 ] . y1 , & a [ 2 ] . x2 , & a [ 2 ] . y2 ) ;
    scanf ( "%ld %ld %ld %ld\n" , & a [ 3 ] . x1 , & a [ 3 ] . y1 , & a [ 3 ] . x2 , & a [ 3 ] . y2 ) ;
    temp1 = intersectie ( a [ 1 ] , a [ 2 ] ) ;
    temp2 = intersectie ( a [ 1 ] , a [ 3 ] ) ;
    temp4 = intersectie ( a [ 2 ] , a [ 3 ] ) ;
    temp3 = intersectie ( temp1 , temp2 ) ;
    printf ( "%lld " , arie ( a [ 1 ] ) + arie ( a [ 2 ] ) + arie ( a [ 3 ] ) - arie ( temp1 )- arie ( temp4 ) - arie ( temp2 ) + arie ( temp3 ) ) ;
    printf ( "%lld\n" , perimetru ( a [ 1 ] ) + perimetru ( a [ 2 ] ) + perimetru ( a [ 3 ] ) - perimetru ( temp1 ) - perimetru ( temp4 ) - perimetru ( temp2 ) + perimetru ( temp3 ) ) ;
}