Pagini recente » Borderou de evaluare (job #2956501) | Borderou de evaluare (job #538608) | Borderou de evaluare (job #3022907) | Borderou de evaluare (job #2853475) | Cod sursa (job #3326167)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("reuniune.in");
ofstream g("reuniune.out");
struct dreptunghi {
int X0,Y0,X1,Y1;
};
inline long long int arie(const dreptunghi &d) {
return 1LL*(d.X1-d.X0)*(d.Y1-d.Y0);
}
inline long long int perimetru(const dreptunghi &d) {
return 2LL*(d.X1-d.X0)+2LL*(d.Y1-d.Y0);
}
dreptunghi intersectie(const dreptunghi &d1,const dreptunghi &d2) {
dreptunghi d;
d.X0=max(d1.X0,d2.X0);
d.Y0=max(d1.Y0,d2.Y0);
d.X1=min(d1.X1,d2.X1);
d.Y1=min(d1.Y1,d2.Y1);
if(d.X0>d.X1||d.Y0>d.Y1) {
d.X0=d.X1=0;
d.Y0=d.Y1=0;
}
return d;
}
int main() {
dreptunghi D[3];
long long int A=0,P=0;
dreptunghi dd;
for(int i=0; i<3; i++) {
f>>D[i].X0>>D[i].Y0>>D[i].X1>>D[i].Y1;
A+=arie(D[i]);
P+=perimetru(D[i]);
}
for(int i=0; i<2; i++) {
for(int j=i+1; j<3; j++) {
dd=intersectie(D[i],D[j]);
A-=arie(dd);
P-=perimetru(dd);
}
}
dd=intersectie(intersectie(D[0],D[1]),D[2]);
A+=arie(dd);
P+=perimetru(dd);
g<<A<<' '<<P;
f.close();
g.close();
return 0;
}