Pagini recente » Cod sursa (job #230359) | Cod sursa (job #2984618) | Cod sursa (job #1051027) | Cod sursa (job #2413126) | Cod sursa (job #2550704)
#include <fstream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <stack>
#define INF 0x3f3f3f3f
using namespace std;
#ifdef DEBUG
string name = "data";
#else
string name = "reuniune";
#endif
ifstream fin(name + ".in");
ofstream fout(name + ".out");
struct Point {
int64_t x, y;
};
struct Rectangle {
Point bottomLeft;
Point topRight;
int64_t area() {
return (topRight.x - bottomLeft.x) * (topRight.y - bottomLeft.y);
}
int64_t perimeter() {
int64_t h = topRight.x - bottomLeft.x;
int64_t v = topRight.y - bottomLeft.y;
if (h == 0) {
return v;
}
if (v == 0) {
return h;
}
return 2 * h + 2 * v;
}
};
bool contains(Rectangle &a, Rectangle &b) {
return b.bottomLeft.x >= a.bottomLeft.x && b.topRight.x <= a.topRight.x && b.bottomLeft.y >= a.bottomLeft.y && b.topRight.y <= a.topRight.y;
}
Rectangle read() {
int x1, y1, x2, y2;
fin >> x1 >> y1 >> x2 >> y2;
return {{x1,y1}, {x2,y2}};
}
Rectangle intersection(Rectangle &a, Rectangle &b) {
if (a.bottomLeft.x > b.bottomLeft.x) {
return intersection(b, a);
}
auto x1 = max(a.bottomLeft.x, b.bottomLeft.x);
auto x2 = min(a.topRight.x, b.topRight.x);
if (x2 <= x1) {
return {{0,0}, {0,0}};
}
auto y1 = max(a.bottomLeft.y, b.bottomLeft.y);
auto y2 = min(a.topRight.y, b.topRight.y);
if (y2 <= y1) {
return {{0,0}, {0,0}};
}
return {{x1,y1}, {x2,y2}};
}
int main() {
Rectangle a = read();
Rectangle b = read();
Rectangle c = read();
Rectangle arr[3] = {a,b,c};
for (int i = 0; i < 3; ++i) {
Rectangle r = arr[i];
int nrCon = 0;
int oIndex = 0;
for (int j = 0; j < 3; ++j) {
if (i == j) {
continue;
}
if (contains(r, arr[j])) {
nrCon++;
} else {
oIndex = j;
}
}
if (nrCon == 2) {
fout << r.area() << " " << r.perimeter();
return 0;
}
if (nrCon == 1) {
Rectangle b = arr[oIndex];
int64_t area = r.area() + b.area() - intersection(r, b).area();
int64_t perimeter = r.perimeter() + b.perimeter() - intersection(r, b).perimeter();
fout << area << " " << perimeter;
return 0;
}
}
auto xab = intersection(a, b);
int64_t xa = intersection(xab, c).area();
int64_t xp = intersection(xab, c).perimeter();
int64_t area = a.area() + b.area() + c.area() - intersection(a, b).area() - intersection(a, c).area() - intersection(b, c).area() + xa;
int64_t perimeter = a.perimeter() + b.perimeter() + c.perimeter() - intersection(a, b).perimeter() - intersection(a, c).perimeter() - intersection(b, c).perimeter() + xp;
fout << area << " " << perimeter;
return 0;
}