Cod sursa(job #2703926)

Utilizator JaguarKatStere Teodor Ioanin JaguarKat Data 9 februarie 2021 15:41:43
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.34 kb
#include <iostream>
#include <fstream>

using namespace std;

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

struct dreptunghi
{
    long long x0, y0, x1, y1;
} d[4];

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

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

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 and c.y0 <= c.y1)return c;
    else
    {
        dreptunghi d;
        d.x0 = d.x1 = d.y0 = d.y1 = 0;
        return d;
    }
    return c;
}

int main()
{
    fin >> d[1].x0 >> d[1].y0 >> d[1].x1 >> d[1].y1;
    fin >> d[2].x0 >> d[2].y0 >> d[2].x1 >> d[2].y1;
    fin >> d[3].x0 >> d[3].y0 >> d[3].x1 >> d[3].y1;
    fout << arie(d[1]) + arie(d[2]) + arie(d[3]) - arie(intersectie(d[1], d[2])) - arie(intersectie(d[2], d[3])) - arie(intersectie(d[3], d[1])) + arie(intersectie(intersectie(d[1], d[2]), d[3]));
    fout << " ";
    fout << perimetru(d[1]) + perimetru(d[2]) + perimetru(d[3]) - perimetru(intersectie(d[1], d[2])) - perimetru(intersectie(d[2], d[3])) - perimetru(intersectie(d[3], d[1])) + perimetru(intersectie(intersectie(d[1], d[2]), d[3]));
    return 0;
}