Cod sursa(job #1947439)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 30 martie 2017 23:00:26
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.56 kb
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;


struct Dreptunghi{
    int xu , yu , xj , yj ;
} ;

Dreptunghi a , b ,c ;


int CalcSurface ( Dreptunghi x ){
    return ( x.xu - x.xj ) * (x.yu - x.yj );

}

int CalcPer ( Dreptunghi x ){
    return 2 * ( x.xu - x.xj + x.yu - x.yj );
}

Dreptunghi CalcIntersec ( Dreptunghi x , Dreptunghi y ){
    Dreptunghi temp ;


    temp.xu = min ( x.xu , y.xu );
    temp.yu = min ( x.yu , y.yu );

    temp.xj = max ( x.xj , y.xj );
    temp.yj = max( x.yj , y.yj );

    if ( temp.xj > temp.xu || temp.yj > temp.yu){
        temp.xj = temp.xu = temp.yj = temp.yu = 0;
    }

    return temp ;

}

int main(){

    freopen("reuniune.in","r",stdin);
    freopen("reuniune.out","w",stdout);

    scanf("%d%d%d%d", &a.xj , &a.yj , &a.xu , &a.yu);
    scanf("%d%d%d%d", &b.xj , &b.yj , &b.xu , &b.yu );
    scanf("%d%d%d%d", &c.xj , &c.yj , &c.xu , &c.yu );

    CalcSurface( CalcIntersec( a , b ) );

    int s = CalcSurface( a ) + CalcSurface( b ) + CalcSurface( c ) - CalcSurface( CalcIntersec( a , b ) )-
            CalcSurface( CalcIntersec( a , c ) ) - CalcSurface( CalcIntersec( c , b ) ) + CalcSurface( CalcIntersec( a , CalcIntersec( b ,c ) ) ) ;

    int per = CalcPer( a ) + CalcPer( b ) + CalcPer( c ) - CalcPer( CalcIntersec( a , b ) )-
                CalcPer( CalcIntersec( a , c ) ) - CalcPer( CalcIntersec( c , b ) ) + CalcPer( CalcIntersec( a , CalcIntersec( b ,c ) ) ) ;

    printf("%d " ,  s );
    printf("%d" , per  );



    return 0;
}