Pagini recente » Cod sursa (job #1320530) | Cod sursa (job #3217622)
#include <bits/stdc++.h>
using namespace std;
FILE *fin, *fout;
struct Point {
int x, y;
void read() {
fscanf(fin, "%d%d", &x, &y);
}
};
struct Rectangle {
Point bottomLeft, upperRight;
void read() {
bottomLeft.read();
upperRight.read();
}
long long perimeter() {
if (bottomLeft.x > upperRight.x || bottomLeft.y > upperRight.y) return 0;
return ((long long)upperRight.x - bottomLeft.x + upperRight.y - bottomLeft.y) * 2;
}
long long area() {
if (bottomLeft.x > upperRight.x || bottomLeft.y > upperRight.y) return 0;
return (long long)(upperRight.x - bottomLeft.x) * (upperRight.y - bottomLeft.y);
}
};
Rectangle intersect(Rectangle r1, Rectangle r2) {
return
{
{max(r1.bottomLeft.x, r2.bottomLeft.x), max(r1.bottomLeft.y, r2.bottomLeft.y)},
{min(r1.upperRight.x, r2.upperRight.x), min(r1.upperRight.y, r2.upperRight.y)}
};
}
int main() {
fin = fopen("reuniune.in", "r");
fout = fopen("reuniune.out", "w");
Rectangle r1, r2, r3;
r1.read();
r2.read();
r3.read();
fprintf(fout, "%lld ", + r1.area() + r2.area() + r3.area()
- intersect(r1, r2).area() - intersect(r1, r3).area() - intersect(r2, r3).area()
+ intersect(intersect(r1, r2), r3).area());
fprintf(fout, "%lld\n", + r1.perimeter() + r2.perimeter() + r3.perimeter()
- intersect(r1, r2).perimeter() - intersect(r1, r3).perimeter() - intersect(r2, r3).perimeter()
+ intersect(intersect(r1, r2), r3).perimeter());
fclose(fin);
fclose(fout);
return 0;
}