Cod sursa(job #2086072)

Utilizator adiaioanaAdia R. adiaioana Data 11 decembrie 2017 12:32:23
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.76 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;
int pm(chestie X);
unsigned long long ar(chestie X);
bool inter(chestie X, chestie Y);
void intersect(chestie X, chestie Y, chestie &XY);
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;
    if(inter(A,B)==0&&inter(B,C)==0&&inter(A,C)==0)
    {
        arr=ar(A)+ar(B)+ar(C);
        pmr=pm(A)+pm(B)+pm(C);
        fout<<arr<<' '<<pmr<<'\n';
        return 0;
    }
    if(inter(A,B)&&inter(B,C)&&inter(A,C))
    {
        intersect(A,B,AB);
        intersect(B,C,BC);
        intersect(A,C,AC);
        intersect(AB,C,T);
        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(AC)-ar(BC)+ar(T);
    }
    else{
        intersect(A,B,AB);
        intersect(B,C,BC);
        intersect(A,C,AC);
        pmr=pm(A)+pm(B)+pm(C)-pm(AB)-pm(BC)-pm(AC);
        arr=ar(A)+ar(B)+ar(C)-ar(AB)-ar(AC)-ar(BC);
    }
    fout<<arr<<' '<<pmr<<'\n';
    return 0;
}
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;
}
int 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;
}
void intersect(chestie X, chestie Y, chestie &XY)
{
    if(inter(X,Y)==0)
        return;
    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);
}
    /*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;
        }
    }*/