2015 Multi-University Training Contest 2 1002 Buildings (HDU5301)

Buildings

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1261    Accepted Submission(s): 341


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(1n,m108,n×m>1,1xn,1ym) .
 

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.
 

Source
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:   5309  5307  5306  5304  5303 
 




题意:

        把一个长m,宽n的矩形,分割成一些小矩形,要求每个小矩形至少有一条边是原来大矩形的边的一部分,除了一个特殊的格子x,y不能被包含在分割后的矩形里,其它部分都必须被分割。问分割出来的矩形的中,面积最大的那个的面积的最小值?

思路:

        如果不考虑那个不能被分割的格子(以下称bad point),那么很容易知道最佳的分割方法如下:


(上图来自官方题解)


        此时的答案是ans(min(m,n)+  1) / 2


        为了考虑bad point的影响,我们先简化这个问题,通过旋转和翻转,使得:

  1. 水平方向的边长大于等于竖直方向(m >= n);
  2. bad point的位置靠左上方(x <= n - x - 1 y  <=m - y + 1)即其离左边的距离不大于右边,离上面的距离不大于下面。

转换前:


转换后


        此时bad point下方的那个点受到bad point的影响最大,导致按原来的分割方法分割出的面积n - x可能大于ans,我们要寻找一种新的方法,尝试减少他的面积。


        我们可以考虑它从左方连接外面,看看此时的面积y是否更小。最终他的面积应该是min(y,n - x))。我们取max(ans,min(y,n - x)),这看起来就是答案。


        但是这样忽略了一种情况,那就是如果大矩形是个正方形,边长为奇数,并且不能分割的块在正中间,此时的答案就是ans-1了。


#include<bits/stdc++.h>
using namespace std;

int main(void) {
    int n,m,x,y;
    while(~scanf("%d%d%d%d",&n,&m,&x,&y)) {

        ///旋转整个矩形,使矩形的n<=m,即x方向的边长于y方向
        if(n > m) {
            swap(n,m);
            swap(x,y);
        }

        ///翻转整个矩形,使不能被分割的那个块靠左上方(原点)
        x = min(x,n - x + 1);
        y = min(y,m - y + 1);

        ///不考虑不能分割的块,答案如下:
        int ans = (n + 1) / 2;

        ///如果大矩形是个正方形,边长为奇数,并且不能分割的块在正中间,
        ///则答案就是原答案减一
        if(n == m && n % 2 == 1 && x == y && x == n / 2 + 1) {
            ans--;


        ///否则,考虑不能分割的块下方的那个块,应该从左方还是下方与外面相连所得矩形的面积更小。
        ///考虑该块相连后的面积与答案的最大值
         } else {
            ans = max(ans,min(y,n - x));
        }
        printf("%d\n",ans);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值