Cod sursa(job #2086077)

Utilizator adiaioanaAdia R. adiaioana Data 11 decembrie 2017 13:00:46
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.73 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
unsigned long long arr,pmr;
struct chestie
{
    int x1,y1,x2,y2;
} A,B,C,AB,BC,AC,T;
unsigned long long pm(chestie X);
unsigned long long ar(chestie X);
bool inter(chestie X, chestie Y);
chestie clean(chestie X);
bool wrong(chestie X);
void daca();
chestie intersect(chestie X, chestie Y);
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;
    daca();
    AB=intersect(A,B);
    BC=intersect(B,C);
    AC=intersect(A,C);
    T=intersect(AB,C);
    pmr=pm(A)+pm(B)+pm(C)-pm(AB)-pm(BC)-pm(AC)+pm(T);
    arr=ar(A)+ar(B)+ar(C)-ar(AB)-ar(BC)-ar(AC)+ar(T);
    fout<<arr<<' '<<pmr<<'\n';
    return 0;
}
bool wrong(chestie X)
{
    if(X.x1>X.x2)
        return 1;
    if(X.y1>X.y2)
        return 1;
    return 0;
}
chestie clean(chestie X)
{
    X.x1=X.x2=X.y1=X.y2=0;
    return X;
}
void daca()
{
    if(wrong(AB)){
        AB=clean(AB);
        T=clean(T);
    }
    if(wrong(AC)){
        AC=clean(AC);
        T=clean(T);
    }
    if(wrong(BC)){
        BC=clean(BC);
        T=clean(T);
    }
    if(wrong(T)){
        T=clean(T);
    }
}
unsigned long long ar(chestie X)
{
    int lg=abs(X.x2-X.x1);
    int lt=abs(X.y2-X.y1);
    unsigned long long aria=lt*lg;
    return aria;
}
unsigned long long pm(chestie X)
{
    int lg=abs(X.x2-X.x1);
    int lt=abs(X.y2-X.y1);
    int P=lt*2+lg*2;
    return P;
}
bool inter(chestie X, chestie Y)
{
    if(Y.y1>X.y2)
        return 0;
    if(Y.y2<X.y1)
        return 0;
    if(Y.x2<X.x1)
        return 0;
    if(Y.x1>X.x2)
        return 0;
    return 1;
}
chestie intersect(chestie X, chestie Y)
{
    chestie XY;
    XY.x1=XY.x2=XY.y1=XY.y2=0;
    XY.x1=max(Y.x1,X.x1);
    XY.x2=min(X.x2,Y.x2);
    XY.y1=max(X.y1,Y.y1);
    XY.y2=min(X.y2,Y.y2);
    return XY;
}
/*if(Y.x1>=X.x1&&Y.x1<=X.x2)
{
    ///1
    if(Y.y1>=X.y1&&Y.y1<=X.y2)
    {
        XY.x1=Y.x1;///min(Y.x1,X.x2)=Y.x1
        XY.x2=min(X.x2,Y.x2);///max(Y.x1,X.x2)=X.x2
        XY.y1=Y.y1;///sunt justificate in functie de if-urile puse
        XY.y2=min(X.y2,Y.y2);
    }
    ///2
    else if(Y.y2>=X.y1&&Y.y2<=X.y2)
    {
        XY.x1=Y.x1;
        XY.x2=min(Y.x2,X.x2);
        XY.y1=max(X.y1,Y.y1);
        XY.y2=Y.y2;
    }
}
else if(Y.x2>=X.x1&&Y.x2<=X.x2)
{
    ///3
    if(Y.y1>=X.y1&&Y.y1<=X.y2)
    {
        XY.x1=max(Y.x1,X.x1);
        XY.x2=Y.x2;
        XY.y1=Y.y1;
        XY.y2=min(Y.y2,X.x2);
    }
    ///4
    else if(Y.y2>=X.y1&&Y.y2<=X.y2)
    {
        XY.x1=X.x1;
        XY.x2=Y.x2;
        XY.y1=X.y1;
        XY.y2=Y.y2;
    }
}*/