Cod sursa(job #3358782)

Utilizator oliviamMarin Olivia oliviam Data 20 iunie 2026 13:07:49
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <cmath>

using namespace std;

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

struct dreptunghi
{
    long long x1, y1, x2, y2, arie, perim;
};

dreptunghi d1, d2, d3, d12, d23, d13, dtotal;

void citire(dreptunghi &d)
{
    f>>d.x1>>d.y1>>d.x2>>d.y2;
}

void calcul(dreptunghi &d)
{
    if(d.x1>d.x2 || d.y1>d.y2)
        return;
    d.arie=abs(d.x1-d.x2)*abs(d.y1-d.y2);
    d.perim=(abs(d.x1-d.x2)+abs(d.y1-d.y2))*2;
}

void intersectie(dreptunghi a, dreptunghi b, dreptunghi &c)
{
    c.x1=max(a.x1, b.x1);
    c.y1=max(a.y1, b.y1);
    c.x2=min(a.x2, b.x2);
    c.y2=min(a.y2, b.y2);
    calcul(c);
}

int main()
{
    citire(d1);
    calcul(d1);
    citire(d2);
    calcul(d2);
    citire(d3);
    calcul(d3);
    intersectie(d1,d2,d12);
    intersectie(d2,d3,d23);
    intersectie(d1,d3,d13);
    intersectie(d12,d13,dtotal);
    g << d1.arie + d2.arie + d3.arie - d12.arie - d23.arie - d13.arie + dtotal.arie << ' '
      << d1.perim + d2.perim + d3.perim - d12.perim - d23.perim - d13.perim + dtotal.perim;
    return 0;
}