Cod sursa(job #1223717)

Utilizator PaueyPaula Nicoleta Gradu Pauey Data 28 august 2014 17:35:17
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <iostream>
#include <fstream>
using namespace std;

struct drept {
    int x1, y1, x2, y2;
};

drept r;

drept intersectie(drept a, drept b){
    r.x1 = max(a.x1, b.x1);
    r.x2 = min(a.x2, b.x2);
    r.y1 = max(a.y1, b.y1);
    r.y2 = min(a.y2, b.y2);
    if(r.x1 > r.x2 || r.y1 > r.y2) r.x1 = r.x2 = r.y1 = r.y2 = 0;
    return r;
}

long long arie(drept d) {
    return (long long) (d.x2 - d.x1) * (d.y2 - d.y1);
}

long long per(drept d) {
    return (long long) (d.x2 - d.x1 + d.y2 - d.y1) * 2;
}

drept v[4];

int main()
{
    ifstream cin("reuniune.in");
    ofstream cout("reuniune.out");
    long long a, p;

    for(int i = 1; i <= 3; ++i) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    }

    p = per(v[1]) + per(v[2]) + per(v[3]) - per(intersectie(v[1], v[2])) - per(intersectie(v[2], v[3])) - per(intersectie(v[1], v[3])) + per(intersectie(intersectie(v[1], v[2]), v[3]));

    a = arie(v[1]) + arie(v[2]) + arie(v[3]) - arie(intersectie(v[1], v[2])) - arie(intersectie(v[2], v[3])) - arie(intersectie(v[1], v[3])) + arie(intersectie(intersectie(v[1], v[2]), v[3]));

    cout << a << ' ' << p;

    return 0;
}