Pagini recente » Cod sursa (job #1541010) | Cod sursa (job #1041031) | Cod sursa (job #213215) | Cod sursa (job #1238315) | Cod sursa (job #1452016)
#include <stdio.h>
#define MIN(A, B) ((A) < (B) ? (A) : (B))
#define MAX(A, B) ((A) > (B) ? (A) : (B))
typedef long long ll;
typedef struct {
int x0, y0; // stanga jos
int x1, y1; // dreapta sus
} retangle;
inline ll surface(const retangle &a) {
if (a.x0 > a.x1 || a.y0 > a.y1) {
return 0;
}
return 1LL * (a.x1 - a.x0) * (a.y1 - a.y0);
}
inline ll perimiter(const retangle &a) {
if (a.x0 > a.x1 || a.y0 > a.y1) {
return 0;
}
return 1LL * (a.x1 - a.x0 + a.y1 - a.y0) << 1;
}
inline retangle intersect(const retangle &a, retangle &b) {
retangle c;
c.x0 = MAX(a.x0, b.x0);
c.y0 = MAX(a.y0, b.y0);
c.x1 = MIN(a.x1, b.x1);
c.y1 = MIN(a.y1, b.y1);
return c;
}
int main(void) {
FILE *f = fopen("reuniune.in", "r");
retangle a, b, c;
fscanf(f, "%d%d%d%d%d%d%d%d%d%d%d%d", &a.x0, &a.y0, &a.x1, &a.y1, &b.x0, &b.y0, &b.x1, &b.y1, &c.x0, &c.y0, &c.x1, &c.y1);
fclose(f);
f = fopen("reuniune.out", "w");
fprintf(f, "%lld %lld\n", surface(a) + surface(b) + surface(c) - surface(intersect(a, b)) - surface(intersect(a, c)) - surface(intersect(b, c)) + surface(intersect(intersect(a, b), c)),
perimiter(a) + perimiter(b) + perimiter(c) - perimiter(intersect(a, b)) - perimiter(intersect(a, c)) - perimiter(intersect(b, c)) + perimiter(intersect(intersect(a, b), c)));
fclose(f);
return 0;
}