2015 Multi-University Training Contest 2 B Buildings(脑洞题)

来源:互联网 发布:红色网络教育家园 编辑:程序博客网 时间:2024/05/21 14:52

Problem Description
Your current task is to make a ground plan for a residential building located in HZXJHS. So you must determine a way to split the floor building with walls to make apartments in the shape of a rectangle. Each built wall must be paralled to the building's sides.

The floor is represented in the ground plan as a large rectangle with dimensions n×m, where each apartment is a smaller rectangle with dimensions a×b located inside. For each apartment, its dimensions can be different from each other. The numbera and b must be integers.

Additionally, the apartments must completely cover the floor without one 1×1 square located on (x,y). The apartments must not intersect, but they can touch.

For this example, this is a sample of n=2,m=3,x=2,y=2.



To prevent darkness indoors, the apartments must have windows. Therefore, each apartment must share its at least one side with the edge of the rectangle representing the floor so it is possible to place a window.

Your boss XXY wants to minimize the maximum areas of all apartments, now it's your turn to tell him the answer.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a, b, x, y, c, d, r;int main(){while(scanf("%d%d%d%d", &a, &b, &x, &y) != EOF){if(a > b) swap(a, b), swap(x, y);r = (a + 1) / 2;c = max(x - 1, a - x);d = min(y, b - y + 1);if(r < d && x - 1 != a - x)  r = min(c, d);if(a == b && (a & 1) && x == y && (x * 2 - 1 == a)) r = a / 2;printf("%d\n", r);}return 0;}

0 0