Pagini recente » Istoria paginii runda/simulare_de_oni_9 | Cod sursa (job #2013366) | Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #531736)
Cod sursa(job #531736)
// http://infoarena.ro/problema/reuniune
#include <fstream>
using namespace std;
#define x first
#define y second
ifstream in("reuniune.in");
ofstream out("reuniune.out");
struct rectangle {
pair<long long,long long> downLeft;
pair<long long,long long> upRight;
};
rectangle intersection(rectangle one,rectangle two);
long long area(rectangle myRectangle);
long long perimeter(rectangle myRectangle);
rectangle first,second,third;
int main() {
in >> first.downLeft.x >> first.downLeft.y >> first.upRight.x >> first.upRight.y;
in >> second.downLeft.x >> second.downLeft.y >> second.upRight.x >> second.upRight.y;
in >> third.downLeft.x >> third.downLeft.y >> third.upRight.x >> third.upRight.y;
out << area(first) + area(second) + area(third)
- area(intersection(first,second))
- area(intersection(second,third))
- area(intersection(first,third))
+ area( intersection (intersection(second,third),first) );
out << " ";
out << perimeter(first) + perimeter(second) + perimeter(third)
- perimeter(intersection(first,second))
- perimeter(intersection(second,third))
- perimeter(intersection(first,third))
+ perimeter( intersection (intersection(second,third),first) );
return (0);
}
rectangle intersection(rectangle one,rectangle two) {
rectangle result;
result.downLeft.x = max(one.downLeft.x,two.downLeft.x);
result.downLeft.y = max(one.downLeft.y,two.downLeft.y);
result.upRight.x = min(one.upRight.x,two.upRight.x);
result.upRight.y = min(one.upRight.y,two.upRight.y);
if(result.downLeft.x > result.upRight.x || result.downLeft.y > result.upRight.y) {
result.upRight = make_pair(0,0);
result.downLeft = make_pair(0,0);
}
return result;
}
long long area(rectangle myRectangle) {
return ((myRectangle.upRight.x - myRectangle.downLeft.x) * (myRectangle.upRight.y - myRectangle.downLeft.y));
}
long long perimeter(rectangle myRectangle) {
return 2 * ((myRectangle.upRight.x - myRectangle.downLeft.x) + (myRectangle.upRight.y - myRectangle.downLeft.y));
}