Cod sursa(job #3125215)

Utilizator AffectiveSmile2Mihnea Matea AffectiveSmile2 Data 2 mai 2023 12:16:39
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");

struct dreptunghi
{
    int X0,Y0,X1,Y1;///X0<=X1,Y0<=Y1
};
inline long long int arie(dreptunghi d)
{
    return 1LL*(d.X1-d.X0)*(d.Y1-d.Y0);
}
inline long long int perimetru(dreptunghi d)
{
    return 2LL*(d.X1-d.X0)+2LL*(d.Y1-d.Y0);
}
dreptunghi intersectie(const dreptunghi &d1,const dreptunghi &d2)
{
    dreptunghi d;
    d.X0=max(d1.X0,d2.X0);
    d.Y0=max(d1.Y0,d2.Y0);
    //
    d.X1=min(d1.X1,d2.X1);
    d.Y1=min(d1.Y1,d2.Y1);
    //
    if(d.X0>d.X1||d.Y0>d.Y1)
    {
        d.X0=d.X1=0;///intersectia e vida
        d.Y0=d.Y1=0;///dreptunghiul "vid"
    }
    return d;
}
int main()
{
    dreptunghi D[3];///datele de intrare
    long long int A=0,P=0;///aria si perimetrul total
    dreptunghi dd;
    for(int i=0;i<3;i++)
    {
        f>>D[i].X0>>D[i].Y0>>D[i].X1>>D[i].Y1;
        A+=arie(D[i]);
        P+=perimetru(D[i]);
    }
    for(int i=0;i<3;i++)
        for(int j=i+1;j<3;j++)
    {
        dd=intersectie(D[i],D[j]);
        A-=arie(dd);
        P-=perimetru(dd);
    }
    dd=intersectie(intersectie(D[0],D[1]),D[2]);
    A+=arie(dd);
    P+=perimetru(dd);
    g<<A<<' '<<P;
    f.close();
    g.close();
    return 0;
}