Cod sursa(job #1390887)

Utilizator BlackLordFMI Alex Oprea BlackLord Data 17 martie 2015 13:45:29
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.19 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");
long long aux, i, a, p;

struct dreptunghi{
    long long x1, x2, y1, y2;
} v[4], x12, x13, x23, x123;

int arie(dreptunghi a){
    return 1LL*(a.x2-a.x1)*(a.y2-a.y1);
}

long long perimetru(dreptunghi x){
    return 2*(1LL*abs(x.x1-x.x2)+1LL*abs(x.y1-x.y2));
}

dreptunghi reuniune(dreptunghi a, dreptunghi b){
    dreptunghi c;
    c.x1=(a.x1>b.x1?a.x1:b.x1);
    c.x2=(a.x2<b.x2?a.x2:b.x2);
    c.y1=(a.y1>b.y1?a.y1:b.y1);
    c.y2=(a.y2<b.y2?a.y2:b.y2);
    if(b.x2<a.x1 || a.x2<b.x1 || b.y2<a.y1 || a.y2<b.y1)
    {
        c.x1=0;
        c.x2=0;
        c.y1=0;
        c.y2=0;
    }
    return c;
}

int main(){
    for(i=1; i<4; i++)
        f>>v[i].x1>>v[i].y1>>v[i].x2>>v[i].y2;
    for(i=1; i<4; i++)
        a+=arie(v[i]);
    x12=reuniune(v[1], v[2]);
    x13=reuniune(v[1], v[3]);
    x23=reuniune(v[2], v[3]);
    x123=reuniune(x12, v[3]);
    a=a-arie(x12)-arie(x13)-arie(x23)+arie(x123);
    p=perimetru(v[1])+perimetru(v[2])+perimetru(v[3])-perimetru(x12)-perimetru(x13)-perimetru(x23)+perimetru(x123);
    g<<a<<' '<<p<<"\n";
    return 0;
}