码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5301 Buildings

时间:2015-07-25 12:21:24      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:hdu   多校   思维   

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301


题面:

Buildings

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


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
 


解题:

    因为方格肯定是1*k的,这样才能让面积最小,一开始,看时限,以为是二分答案。但发现若没有坏点,那么答案就是ans=(min(n,m)+1)/2。但有坏点,会出现两种特殊情况。

1.n等于m,且n为奇数,同时坏点在中心点位置,那么答案就为ans-1;

2.(假设n>m)坏点所在的位置,形成的面向4条边框的距离中,总长为m-1的两条中的一条大于ans,且该条边所在位置,不能由上或下覆盖,那么就取三个方向上离该点(那条无法覆盖的边上离坏点最近的那个点)最近的距离为答案。

3.其余情况,答案都为ans不变。


总结:

    其实,比赛的时候,以上两种特殊情况,都已经找到了,但是,思路太乱,造成不能理性得分析问题。这种问题,应该有条理地进行分析,讨论。想好了再去动手写。


代码:

#include <iostream>
#include <cmath>
using namespace std;
int max(int a,int b)
{
    return a>b?a:b;
}
int min(int a,int b)
{
    return a<b?a:b;
}
int main()
{
    int n,m,x,y,ans;
    while(cin>>n>>m>>x>>y)
    {
      ans=(min(n,m)+1)/2;
      if(n==m)
      {
        if(n%2)
        {
            if(x==(n+1)/2&&y==(m+1)/2)
                ans--;
        }
      }
      else
      {
          int le,ri,up,dw;
          if(n<m)
          {
             swap(n,m);
             swap(x,y);
          }
          le=y;
          ri=m-y+1;
          up=x;
          dw=n-x+1;
          if(m%2)
          {
              if(abs(le-ans)>1)
              {
                  if(up>ans&&dw>ans)
                  {
                      ans=max(le-1,ri-1);
                      ans=min(ans,up);
                      ans=min(ans,dw);
                  }
              }
          }
          else
          {
              if(!(le==ans||le==ans+1))
              {
                  if(up>ans&&dw>ans)
                  {
                      ans=max(le-1,ri-1);
                      ans=min(ans,up);
                      ans=min(ans,dw);
                  }
              }
          }
      }
      cout<<ans<<endl;
    }
    return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 5301 Buildings

标签:hdu   多校   思维   

原文地址:http://blog.csdn.net/david_jett/article/details/47054749

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!