Pagini recente » Cod sursa (job #2650116) | Cod sursa (job #983811) | Cod sursa (job #1102381) | Cod sursa (job #523276) | Cod sursa (job #804081)
Cod sursa(job #804081)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
class Rect {
public:
Rect() {};
Rect(int, int, int, int);
long long computeArea();
long long computeAmbit();
int x1, x2, y1, y2;
};
Rect::Rect(int xpi, int ypi, int xpf, int ypf) {
x1 = xpi, y1 = ypi, x2 = xpf, y2 = ypf;
}
long long Rect::computeAmbit() {
return 2 * (x2 - x1 + y2 - y1);
}
long long Rect::computeArea() {
return (x2 - x1) * (y2 - y1);
}
Rect operator%(const Rect &lhs, const Rect &rhs) {
Rect meet(max(lhs.x1, rhs.x1), max(lhs.y1, rhs.y1),
min(lhs.x2, rhs.x2), min(lhs.y2, rhs.y2));
if (meet.x1 > meet.x2 || meet.y1 > meet.y2) {
meet.x1 = meet.x2 = meet.y1 = meet.y2 = 0;
}
return meet;
}
int main(int argc, char const *argv[])
{
Rect dr[3];
long long area = 0, ambit = 0;
for (int i = 0; i < 3; ++i) {
fin >> dr[i].x1 >> dr[i].y1 >> dr[i].x2 >> dr[i].y2;
area += dr[i].computeArea();
ambit += dr[i].computeAmbit();
}
Rect meet1, meet2, meet3, meetAll;
meet1 = dr[0] % dr[1];
meet2 = dr[0] % dr[2];
meet3 = dr[1] % dr[2];
meetAll = dr[0] % dr[1] % dr[2];
area -= meet1.computeArea() + meet2.computeArea() + meet3.computeArea();
area += meetAll.computeArea();
ambit -= meet1.computeAmbit() + meet2.computeAmbit() + meet3.computeAmbit();
ambit += meetAll.computeAmbit();
fout << area << ' ' << ambit;
return 0;
}