Pagini recente » Cod sursa (job #1712953) | Cod sursa (job #2766891) | Cod sursa (job #716825) | Cod sursa (job #1791627) | Cod sursa (job #1159057)
#include <fstream>
#include <vector>
#include <iostream>
using namespace std;
ifstream fin ("reuniune.in");
ofstream fout ("reuniune.out");
typedef long long ull;
struct dreptunghi {
ull x1, x2, y1, y2;
} v[3];
bool ok;
ull aria, perim;
dreptunghi intersect (dreptunghi a, dreptunghi b) {
dreptunghi sol;
bool okx = 0, oky = 0;
sol.x1 = sol.x2 = sol.y1 = sol.y2 = 0;
if (a.x1 < b.x1) {
if (b.x1 <= a.x2) {
sol.x1 = b.x1;
sol.x2 = min(b.x2, a.x2);
okx = 1;
}
}
else {
if (a.x1 <= b.x2) {
sol.x1 = a.x1;
sol.x2 = min(a.x2, b.x2);
okx = 1;
}
}
if (a.y1 < b.y1) {
if (b.y1 <= a.y2) {
sol.y1 = b.y1;
sol.y2 = min(b.y2, a.y2);
oky = 1;
}
}
else {
if (a.y1 <= b.y2) {
sol.y1 = a.y1;
sol.y2 = min(a.y2, b.y2);
oky = 1;
}
}
ok = okx & oky;
return sol;
}
int main() {
for (int i = 0; i < 3; ++i)
fin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
for (int i = 1; i < 8; ++i) {
ok = 1;
vector <int> x;
int nr = 0;
for (int j = 0; (1 << j) <= i; ++j)
if (i & (1 << j)) {
nr++;
x.push_back (j);
}
dreptunghi now = v[x[0]];
for (int i = 1; i < x.size(); ++i)
now = intersect (now, v[x[i]]);
ull aria_now = (now.x2 - now.x1) * (now.y2 - now.y1);
ull perim_now = (now.x2 - now.x1 + now.y2 - now.y1) * 2;
if (!ok)
continue;
if (nr % 2 == 0) {
aria -= aria_now;
perim -= perim_now;
}
else {
aria += aria_now;
perim += perim_now;
}
}
fout << aria << " " << perim;
}