Cod sursa(job #1202212)

Utilizator cristian.caldareaCaldarea Cristian Daniel cristian.caldarea Data 27 iunie 2014 12:28:48
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.66 kb
#include <iostream>
#include <fstream>
#include <algorithm>

using namespace std;

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

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

void intersect(Drept &to, const Drept &a, const Drept &b);


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

inline 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;
    f>>a.x0>>a.y0>>a.x1>>a.y1;
    f>>b.x0>>b.y0>>b.x1>>b.y1;
    f>>c.x0>>c.y0>>c.x1>>c.y1;

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

    g<<arie(a)+arie(b)+arie(c)-arie(axb)-arie(axc)-arie(bxc)+arie(axbxc)<<' ';
    g<<perim(a)+perim(b)+perim(c)-perim(axb)-perim(axc)-perim(bxc)+perim(axbxc)<<'\n';
    f.close();
    g.close();
    return 0;
}
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){ to.x0=0; to.x1=0; to.y0=0; to.y1=0; }

}