Cod sursa(job #2498442)

Utilizator bostanlucastefanBostan Luca-Stefan bostanlucastefan Data 23 noiembrie 2019 22:00:27
Problema Reuniune Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <climits>

using namespace std;

ifstream fin("reuniune.in");
ofstream fout("reuniune.out");

long long A,P;

struct dreptunghi
{
    int x,y,x1,y1;
}a[4];

dreptunghi arie(dreptunghi a,dreptunghi b)
{
    dreptunghi r={  max(a.x,b.x)     ,
                    max(a.y,b.y)     ,
                    min(b.x1,a.x1)   ,
                    min(a.y1,b.y1)   };

    if(r.x>r.x1 || r.y>r.y1)
        r={0,0,0,0};
    return r;
}

long long obtARIE(dreptunghi a)
{
    return (a.x1-a.x)*(a.y1-a.y);
}

long long obtPERIMETRU(dreptunghi a)
{
    return ((a.x1-a.x)+(a.y1-a.y))*2;
}

int main()
{
    for(short int i=1 ; i<=3; i++)
    {
        fin>>a[i].x>>a[i].y;
        fin>>a[i].x1>>a[i].y1;

        A+=obtARIE(a[i]);
        P+=obtPERIMETRU(a[i]);
    }

    A-=obtARIE(arie(a[1],a[2]))+obtARIE(arie(a[1],a[3]))+obtARIE(arie(a[2],a[3]))-obtARIE(arie(a[1],arie(a[2],a[3])));
    P-=obtPERIMETRU(arie(a[1],a[2]))+obtPERIMETRU(arie(a[1],a[3]))+obtPERIMETRU(arie(a[2],a[3]))-obtPERIMETRU(arie(a[1],arie(a[2],a[3])));

    fout<<A<<' '<<P;
    return 0;
}