Cod sursa(job #1988214)

Utilizator llalexandruLungu Alexandru Ioan llalexandru Data 2 iunie 2017 14:04:42
Problema Reuniune Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>

using namespace std;

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

struct Punct{long long x, y;};

long long Arie(Punct A, Punct B)
{
    return (B.x-A.x)*(B.y-A.y);
}

long long Perim(Punct A, Punct B)
{
    return 2*((B.x-A.x)+(B.y-A.y));
}

struct Drept{
    Punct A, B;
    long long p, a;
    void calc()
    {
        p=Perim(A, B);
        a=Arie(A, B);
    }
};

Drept r1, r2, r3, r12, r23, r31, r123;

Drept Inter(Drept r1, Drept r2)
{
    Drept r;
    r.A.x=max(r1.A.x, r2.A.x);
    r.A.y=max(r1.A.y, r2.A.y);
    r.B.x=min(r1.B.x, r2.B.x);
    r.B.y=min(r1.B.y, r2.B.y);
    r.calc();
    return r;
}

void Read(Drept& r)
{
    Punct A, B;
    fin>>A.x>>A.y>>B.x>>B.y;
    r.A=A;
    r.B=B;
    r.calc();
}

int main()
{
    Read(r1);
    Read(r2);
    Read(r3);
    r12=Inter(r1, r2);
    r23=Inter(r2, r3);
    r31=Inter(r3, r1);
    r123=Inter(r12, r23);
    long long a=r1.a+r2.a+r3.a-r12.a-r23.a-r31.a+r123.a;
    long long p=r1.p+r2.p+r3.p-r12.p-r23.p-r31.p+r123.p;
    fout<<a<<" "<<p;
    return 0;
}