Pagini recente » Cod sursa (job #69435) | Cod sursa (job #259833) | Cod sursa (job #1720560) | Cod sursa (job #1747142) | Cod sursa (job #838650)
Cod sursa(job #838650)
#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 ) ) ;
}