Pagini recente » Cod sursa (job #2726212) | Cod sursa (job #1593118) | Profil UAIC_Popa_Padurariu_Pavaloi | Cod sursa (job #1626003) | Cod sursa (job #3128403)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("reuniune.in");
ofstream g ("reuniune.out");
struct drept {
int x1, y1, x2, y2;
};
int arie(drept A) {
return 1LL * (A.x2 - A.x1) * (A.y2 - A.y1);
}
int perimetru(drept A) {
return 2LL * (A.x2 - A.x1) + 2LL * (A.y2 - A.y1);
}
drept intersectie(const drept &d1, const drept &d2) {
drept d;
d.x1 = max(d1.x1, d2.x1);
d.y1 = max(d1.y1, d2.y1);
d.x2 = min(d1.x2, d2.x2);
d.y2 = min(d1.y2, d2.y2);
if (d.x1 > d.x2 || d.y1 > d.y2) {
d.x1 = d.x2 = 0;
d.y1 = d.y2 = 0;
}
return d;
}
int main()
{
drept D[3];
long long int A = 0, P = 0;
drept dd;
for (int i = 0; i < 3; i++) {
f >> D[i].x1 >> D[i].y1 >> D[i].x2 >> D[i].y2;
A += arie(D[i]);
P += perimetru(D[i]);
}
for (int i = 0; i < 2; i++) {
for (int j = i + 1; j < 3; j++) {
dd = intersectie(D[i], D[j]);
A -= arie(dd);
P -= perimetru(dd);
}
}
dd = intersectie(intersectie(D[0], D[1]), D[2]);
A += arie(dd);
P += perimetru(dd);
g << A << ' ' << P;
f.close();
g.close();
return 0;
}