您的位置:首页 > 产品设计 > UI/UE

HDU 5301 Building (找规律)

2015-07-24 09:51 411 查看


Buildings

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 739 Accepted Submission(s): 203



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 number a 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.

Input

There are at most 10000 testcases.

For each testcase, only four space-separated integers, n,m,x,y(1≤n,m≤108,n×m>1,1≤x≤n,1≤y≤m).

Output

For each testcase, print only one interger, representing the answer.

Sample Input

2 3 2 2
3 3 1 1


Sample Output

1
2

Hint
Case 1 :



You can split the floor into five 1×1 apartments. The answer is 1.

Case 2:



You can split the floor into three 2×1 apartments and two 1×1 apartments. The answer is 2.



If you want to split the floor into eight 1×1 apartments, it will be unacceptable because the apartment located on (2,2) can't have windows.


题目大意:一个n*m的大格子,删除一个位于(x,y)的小方格,然后用矩形分割剩余的格子。要求分割出的矩形至少有一边在原格子的边缘上。求所用满足分割条件的方法中面积最大矩形的最小值。



解题思路:假设n<=m,我们可以发现用来分割矩形的格子都可以分为1Xk(k>=1),因为如果出现了被分成为aXb的格子,为了得到最小的最大面积,我们可以把aXb的格子再次分成a个1Xb的格子或者b个1Xa的格子。
如果没有被删除的小方格,那么结果应该是(n+1)/2(如果n是奇数,为(n+1)/2;如果n是偶数,为n/2);如果 min(左边,右边)>(n+1)/2并且被删除的格子不在上下的中间位置,那么结果为min(max(左边,右边),min(上边,下边));如果删除的格子位于大格子的中心(即格子为方格(n=m);n,m为奇数;),那么结果为(n+1)/2-1;其他情况,结果为(n+1)/2。
代码如下:
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#include <limits.h>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-4)
#define inf (1<<28)
#define sqr(x) (x) * (x)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
int main()
{
int n,m,x,y,ans;
while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF)
{
//保证n<=m
if(n>m)
{
swap(n,m);
swap(x,y);
}
//不删除格子的结果
ans=(n+1)/2;
//
if(min(y,m-y+1)>ans&&x-1!=n-x)
ans=min(max(x-1,n-x),min(y,m-y+1));
//格子是方格,删除的格子在上下左右的中间
if(n%2&&n==m&&y==(n+1)/2&&x==(n+1)/2)
ans=ans-1;
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: