Cod sursa(job #2983403)

Utilizator alexscanteieScanteie Alexandru alexscanteie Data 22 februarie 2023 13:15:03
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("reuniune.in");
ofstream g("reuniune.out");

struct dreptunghi
{
    long long buttom_x=0,buttom_y=0,top_x=0,top_y=0;
}d[4];

dreptunghi intersectie(dreptunghi A, dreptunghi B)
{
    dreptunghi C,D;
    C.buttom_x=max(A.buttom_x,B.buttom_x);
    C.buttom_y=max(A.buttom_y,B.buttom_y);
    C.top_x=min(A.top_x,B.top_x);
    C.top_y=min(A.top_y,B.top_y);
    if(C.buttom_x<=C.top_x && C.buttom_y<=C.top_y)
        return C;
    return D;
}

long long arie(dreptunghi A)
{
    return (A.top_x-A.buttom_x)*(A.top_y-A.buttom_y);
}

long long p(dreptunghi A)
{
    return 2*(A.top_x-A.buttom_x)+2*(A.top_y-A.buttom_y);
}

int main()
{

    for(int i=1;i<=3;i++)
    {
        f>>d[i].buttom_x>>d[i].buttom_y>>d[i].top_x>>d[i].top_y;
    }
    dreptunghi A=d[1],B=d[2],C=d[3];
    g<<arie(A)+arie(B)+arie(C)-arie(intersectie(A,B))-arie(intersectie(A,C))-arie(intersectie(B,C))+arie(intersectie(intersectie(A,B),C))<<' ';
    g<<p(A)+p(B)+p(C)-p(intersectie(A,B))-p(intersectie(A,C))-p(intersectie(C,B))+p(intersectie(A,intersectie(B,C)));
    return 0;
}