Pagini recente » Monitorul de evaluare | Istoria paginii utilizator/viktor10012001 | Statistici Andrei Ardeleanu (Andrei2138) | Diferente pentru tema intre reviziile 125 si 126 | Cod sursa (job #2013271)
#include <fstream>
using namespace std;
struct Rectangle
{
int64_t top, bot, left, right;
int64_t Perimeter() const { return 2 * abs(right - left) + 2 * abs(top - bot); }
int64_t Area() const { return abs(right - left) * abs(top - bot); }
};
inline void ReadRectangle(ifstream &fin, Rectangle &rect)
{
fin >> rect.bot >> rect.left >> rect.top >> rect.right;
}
inline bool Correct(const Rectangle &rect)
{
return (rect.top >= rect.bot) && (rect.left <= rect.right);
}
Rectangle Intersection(const Rectangle &a, const Rectangle &b)
{
Rectangle intersection;
intersection.top = min(a.top, b.top);
intersection.bot = max(a.bot, b.bot);
intersection.left = max(a.left, b.left);
intersection.right = min(a.right, b.right);
return intersection;
}
int main()
{
ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
Rectangle a, b, c;
ReadRectangle(fin, a);
ReadRectangle(fin, b);
ReadRectangle(fin, c);
auto area = a.Area() + b.Area() + c.Area();
auto perim = a.Perimeter() + b.Perimeter() + c.Perimeter();
auto iab = Intersection(a, b);
auto iac = Intersection(a, c);
auto ibc = Intersection(b, c);
if (Correct(iab)) {
area -= iab.Area();
perim -= iab.Perimeter();
}
if (Correct(iac)) {
area -= iac.Area();
perim -= iac.Perimeter();
}
if (Correct(ibc)) {
area -= ibc.Area();
perim -= ibc.Perimeter();
}
if (Correct(iab) && Correct(iac)) {
auto iabc = Intersection(iab, iac);
if (Correct(iabc)) {
area += iabc.Area();
perim += iabc.Perimeter();
}
}
fout << area << " " << perim << "\n";
return 0;
}