Cod sursa(job #1212371)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 24 iulie 2014 15:32:19
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.11 kb
#include <iostream>
#include <fstream>

using namespace std;

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

struct Drept
{
    long long x0, x1, y0, y1;
};

void intersect(Drept &to, const Drept &a, const Drept &b)
{
    bool r = false;

    if(a.x0 <= b.x0)
    {
        if(a.x1 < b.x0) r = true;
        else
            if(a.x1 == b.x0)
            {
                to.x0 = a.x1;
                to.x1 = a.x1;
            }
            else
            {
                to.x0 = b.x0;
                to.x1 = min(a.x1,b.x1);
            }
    }
    else
    {
        if(b.x1 < a.x0) r = true;
        else
            if(b.x1 == a.x0)
            {
                to.x0 = b.x1;
                to.x1 = b.x1;
            }
            else
            {
                to.x0 = a.x0;
                to.x1 = min(a.x1,b.x1);
            }

    }

    if(a.y0 <= b.y0)
    {
        if(a.y1 < b.y0) r = true;
        else
            if(a.y1 == b.y0)
            {
                to.y0 = a.y1;
                to.y1 = a.y1;
            }
            else
            {
                to.y0 = b.y0;
                to.y1 = min(a.y1,b.y1);
            }
    }
    else
    {
        if(b.y1 < a.y0) r = true;
        else if(b.y1 == a.y0)
        {
            to.y0 = b.y1;
            to.y1 = b.y1;
        }
        else
        {
            to.y0 = a.y0;
            to.y1 = min(a.y1,b.y1);
        }

    }
    if(r)
    {//is true
        to.x0 = 0;
        to.x1 = 0;
        to.y0 = 0;
        to.y1 = 0;
    }

}

long long arie(const Drept &d)
{
    return (d.x1-d.x0)*(d.y1-d.y0);
}

long long perim(const Drept &d)
{
    return 2*(d.x1-d.x0+d.y1-d.y0);
}


int main()
{
    Drept a,b,c,axb,bxc,axc,axbxc;
    fin >> a.x0 >> a.y0 >> a.x1 >>a.y1;
    fin >> b.x0 >> b.y0 >> b.x1 >>b.y1;
    fin >> c.x0 >> c.y0 >> c.x1 >>c.y1;

    intersect(axb,a,b);
    intersect(bxc,b,c);
    intersect(axc,a,c);
    intersect(axbxc,axc,axb);

    fout << arie(a)+arie(b)+arie(c)-arie(axb)-arie(axc)-arie(bxc)+arie(axbxc) << " ";
    fout << perim(a)+perim(b)+perim(c)-perim(axb)-perim(axc)-perim(bxc)+perim(axbxc) << " ";
    return 0;
}