Pagini recente » Cod sursa (job #3153175) | Cod sursa (job #899244) | Cod sursa (job #1040472) | Cod sursa (job #183218) | Cod sursa (job #236795)
Cod sursa(job #236795)
#include <stdio.h>
#include <algorithm>
using namespace std;
struct dreptunghi {
long long x1, y1, x2, y2;
};
dreptunghi a, b, c;
dreptunghi inter(dreptunghi a, dreptunghi b);
long long arie(dreptunghi a);
long long per(dreptunghi a);
int main() {
freopen("reuniune.in", "r", stdin);
freopen("reuniune.out", "w", stdout);
scanf("%lld %lld %lld %lld", &a.x1, &a.y1, &a.x2, &a.y2);
scanf("%lld %lld %lld %lld", &b.x1, &b.y1, &b.x2, &b.y2);
scanf("%lld %lld %lld %lld", &c.x1, &c.y1, &c.x2, &c.y2);
long long ar = 0, p = 0;
ar += (arie(a) + arie(b) + arie(c));
p += (per(a) + per(b) + per(c));
dreptunghi aux;
aux = inter(a, b);
ar -= arie(aux);
p -= per(aux);
aux = inter(b, c);
ar -= arie(aux);
p -= per(aux);
aux = inter(c, a);
ar -= arie(aux);
p -= per(aux);
aux = inter(a, b);
aux = inter(aux, c);
ar += arie(aux);
p += per(aux);
printf("%lld %lld", ar, p);
return 0;
}
dreptunghi inter(dreptunghi a, dreptunghi b) {
if ((b.x1 > a.x2) || (b.x2 < a.x1) || (b.y1 > a.y2) || (b.y2 < a.y1)) {
dreptunghi c;
c.x1 = 0;
c.y1 = 0;
c.x2 = 0;
c.y2 = 0;
return c;
}
long long vx[5], vy[5];
vx[1] = a.x1;
vx[2] = a.x2;
vx[3] = b.x1;
vx[4] = b.x2;
sort(vx + 1, vx + 5);
vy[1] = a.y1;
vy[2] = a.y2;
vy[3] = b.y1; vy[4] = b.y2;
sort(vy, vy + 5);
dreptunghi d;
d.x1 = vx[2]; d.y1 = vy[2]; d.x2 = vx[3]; d.y2 = vy[3];
return d;
}
long long arie(dreptunghi a) {
return ( (a.x2 - a.x1) * (a.y2 - a.y1) );
}
long long per(dreptunghi a) {
return ( 2 * (a.x2 - a.x1) + 2 * (a.y2 - a.y1) );
}