Cod sursa(job #1667879)

Utilizator emanuel_rRamneantu Emanuel emanuel_r Data 29 martie 2016 12:23:14
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include<iostream>
#include<fstream>
#include<vector>
#include<queue>

using namespace std;

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

struct dreptunghi
{
    long long x1, y1, x2, y2;
};

dreptunghi a, b, c;

void Read()
{
    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;
}

dreptunghi intersection(dreptunghi i, dreptunghi j)
{
    dreptunghi aux;
    aux.x1 = aux.x2 = aux.y1 = aux.y2 = 0;

    if(i.x1 > j.x2 || j.x1 > i.x2 || i.y1 > j.y2 || j.y1 > i.y2)
        return aux;

    aux.x1 = max(i.x1, j.x1);
    aux.x2 = min(i.x2, j.x2);
    aux.y1 = max(i.y1, j.y1);
    aux.y2 = min(i.y2, j.y2);

    return aux;
}

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

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

void Solve()
{
    long long FL = 0, P = 0;

    FL += arie(a) + arie(b) + arie(c);
    FL -= (arie(intersection(a, b)) + arie(intersection(a, c)) + arie(intersection(c, b)));
    FL += arie(intersection(a, intersection(b, c)));

    P += perimetru(a) + perimetru(b) + perimetru(c);
    P -= (perimetru(intersection(a, b)) + perimetru(intersection(a, c)) + perimetru(intersection(c, b)));
    P += perimetru(intersection(a, intersection(b, c)));

    g<<FL<<" "<<P<<"\n";
}

int main()
{
    Read();
    Solve();
    return 0;
}