Cod sursa(job #779535)

Utilizator tester9x9Tester9x9 tester9x9 Data 17 august 2012 23:01:51
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <fstream>
#include <cstring>
#include <algorithm>
#define LL long long

using namespace std;

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

struct Drept
{
    LL x1,y1,x2,y2;
};

Drept A,B,C;
Drept AxB,AxC,BxC,AxBxC;

LL S,P;

LL M[20][20];
LL X[20],Y[20],x,y;


Drept Reunite (const Drept& A, const Drept& B)
{
    Drept R;
    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<A.x1 || R.x1<B.x1 || R.x2>A.x2 || R.x2>B.x2 || R.y1<A.y1 || R.y1<B.y1 || R.y2>A.y2 || R.y2>B.y2)
    {
        R.x1=R.x2=R.y1=R.y2=2000000000;
    }
    return R;

}

LL Area (const Drept &A)
{
    return max(0LL,(A.x2-A.x1)*(A.y2-A.y1));
}

LL Perimeter (const Drept &A)
{
    return max(0LL,2*(A.x2-A.x1+A.y2-A.y1));
}

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

    AxB=Reunite(A,B);
    AxC=Reunite(A,C);
    BxC=Reunite(B,C);

    AxBxC=Reunite(AxB,C);

    S=Area(A)+Area(B)+Area(C)-Area(AxB)-Area(AxC)-Area(BxC)+Area(AxBxC);
    P=Perimeter(A)+Perimeter(B)+Perimeter(C)-Perimeter(AxB)-Perimeter(AxC)-Perimeter(BxC)+Perimeter(AxBxC);

    g << S << ' ' << P << '\n';
    f.close();
    g.close();
    return 0;
}