Cod sursa(job #911272)

Utilizator mazaandreiAndrei Mazareanu mazaandrei Data 11 martie 2013 14:41:52
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include<fstream>
using namespace std;
struct dr{long long x1,y1,x2,y2;} d[4];
long long A,P;
long long arie(dr who){return   (who.x2-who.x1) * (who.y2-who.y1);}
long long peri(dr who){return 2*(who.x2-who.x1)+2*(who.y2-who.y1);}
dr ins(dr a, dr b){
    dr s;
    s.x1=max(a.x1,b.x1);
    s.y1=max(a.y1,b.y1);
    s.x2=min(a.x2,b.x2);
    s.y2=min(a.y2,b.y2);
    if (s.x1 > s.x2 ||s.y1 > s.y2)
        return (dr){0,0,0,0};
    return s;
}
int main(){
    ifstream in("reuniune.in"); ofstream out("reuniune.out");
    for(int i=1;i<=3;++i) in>>d[i].x1>>d[i].y1>>d[i].x2>>d[i].y2;
    A= arie(d[1])+arie(d[2])+arie(d[3])- arie(ins(d[1],d[2]))-arie(ins(d[1],d[3]))-arie(ins(d[2],d[3]))+ arie(ins(ins(d[1],d[2]),d[3]));
    P= peri(d[1])+peri(d[2])+peri(d[3])- peri(ins(d[1],d[2]))-peri(ins(d[1],d[3]))-peri(ins(d[2],d[3]))+ peri(ins(ins(d[1],d[2]),d[3]));
    out<<A<<' '<<P<<'\n';
    out.close(); return 0;
}