Cod sursa(job #2224162)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 23 iulie 2018 12:16:06
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <fstream>

using namespace std;

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

struct dreptunghi {
    int x0, y0, x1, y1; /// x0 <= x1, y0 <= y1;
};

inline long long arie(const dreptunghi &d) {
    return 1LL * (d.x1 - d.x0) * (d.y1 - d.y0);
}

inline long long perimetru(const dreptunghi &d) {
    return 2LL * (d.x1 - d.x0 + d.y1 - d.y0);
}

dreptunghi intersectie(const dreptunghi &d1, const dreptunghi &d2) {
    dreptunghi d;
    d.x0 = max(d1.x0, d2.x0);
    d.x1 =  min(d1.x1, d2.x1);
    d.y0 = max(d1.y0, d2.y0);
    d.y1 = min(d1.y1, d2.y1);
    if(d.x0 > d.x1 || d.y0 > d.y1) {
        d.x0 = d.x1 = 0;
        d.y0 = d.y1 = 0;
    }
    return d;
}

int main()
{
    dreptunghi d[3];
    long long a = 0, p = 0;
    dreptunghi dd;
    for(int i = 0; i < 3; i++) {
        in >> 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 < 2; 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);
    out << a << ' ' << p;
    return 0;
}