Cod sursa(job #1497470)

Utilizator CiurezAndreiCiurez Marius-Andrei CiurezAndrei Data 6 octombrie 2015 21:10:44
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include <fstream>

using namespace std;

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

struct dreptunghi{

    long long x1,y1,x2,y2;

}A, B, C, AB, AC, BC, D;

long long arie(dreptunghi P)
{
    return ((P.x2 - P.x1) * (P.y2 - P.y1));
}

long long perimetru(dreptunghi P)
{
    return 2 * ((P.x2 - P.x1) + (P.y2 - P.y1));
}

void intersectie(dreptunghi D1, dreptunghi D2, dreptunghi &D3)
{
    D3.x1 = max(D1.x1, D2.x1);
    D3.y1 = max(D1.y1, D2.y1);
    D3.x2 = min(D1.x2, D2.x2);
    D3.y2 = min(D1.y2, D2.y2);

    if( D3.x1 > D3.x2 || D3.y1 > D3.y2)
    {
        D3.x1 = 0;
        D3.x2 = 0;
        D3.y1 = 0;
        D3.y2 = 0;
    }


}

int main()
{
    fin >> A.x1 >> A.y1 >> A.x2 >> A.y2;
    fin >> B.x1 >> B.y1 >> B.x2 >> B.y2;
    fin >> C.x1 >> C.y1 >> C.x2 >> C.y2;

    intersectie(A, B, AB);
    intersectie(A, C, AC);
    intersectie(B, C, BC);
    intersectie(AB, C, D);

    fout << arie (A) + arie(B) + arie(C) - arie(AB) - arie(AC) - arie(BC) + arie(D) << " ";
    fout << perimetru(A) + perimetru(B) + perimetru(C) - perimetru(AB) - perimetru(AC) - perimetru(BC) + perimetru(D);


    return 0;
}