Cod sursa(job #2703919)

Utilizator andreibazavanAndrei Bazavan andreibazavan Data 9 februarie 2021 15:34:15
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
struct dreptunghi{
    long long x0,y0,x1,y1;
}d[5];

long long perimetru(dreptunghi a)
{
    return (a.x1-a.x0+a.y1-a.y0)*2;
}

long long arie(dreptunghi a)
{
    return (a.x1-a.x0)*(a.y1-a.y0);
}

dreptunghi intersectie(dreptunghi a, dreptunghi b)
{
    dreptunghi c;
    c.x0=max(a.x0,b.x0);
    c.y0=max(a.y0,b.y0);
    c.x1=min(a.x1,b.x1);
    c.y1=min(a.y1,b.y1);
    if(c.x0>c.x1 || c.y0>c.y1) c.x0=c.x1=c.y0=c.y1=0;
    return c;
}
int main()
{
    for(int i=1;i<=3;++i)
        fin>>d[i].x0>>d[i].y0>>d[i].x1>>d[i].y1;
    fout<<arie(d[1])+arie(d[2])+arie(d[3])-arie(intersectie(d[1],d[2]))-arie(intersectie(d[3],d[2]))-arie(intersectie(d[1],d[3]))+arie(intersectie(intersectie(d[1],d[2]),d[3]))<<' ';
    fout<<perimetru(d[1])+perimetru(d[2])+perimetru(d[3])-perimetru(intersectie(d[1],d[2]))-perimetru(intersectie(d[3],d[2]))-perimetru(intersectie(d[1],d[3]))+perimetru(intersectie(intersectie(d[1],d[2]),d[3]))<<'\n';
    return 0;
}