HDU 5301 Buildings

题目链接: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(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.


 

Source

2015 Multi-University Training Contest 2

解题:

因为方格肯定是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;
}

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

时间: 2024-10-19 11:09:25

HDU 5301 Buildings的相关文章

hdu 5301 Buildings (2015多校第二场第2题) 简单模拟

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 题意:给你一个n*m的矩形,可以分成n*m个1*1的小矩形,再给你一个坐标(x,y),表示黑格子在n*m矩形中的位置,黑格子占一个1*1的小矩形的空间,用各种矩形去填充n*m矩形,(x,y)位置不能填,且每个去填充的小矩形都有一边是靠着n*m矩形的外框,求这些填充的小矩形在最小大小情况下的面积最大的矩形面积. 思路:要是填充的矩形大小最小,那么靠近边框的长度一定为1,所以只要判断在矩形内部的长

HDU 5301 Buildings(2015多校第二场)

Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 759    Accepted Submission(s): 210 Problem Description Your current task is to make a ground plan for a residential building located

bzoj4302 Hdu 5301 Buildings

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=4302 [题解] 出自2015多校-学军 题意大概是给出一个n*m的格子有一个格子(x,y)是坏的,用一些矩形覆盖没有坏的格子,使得每个矩形都有一面靠着边界.求最大的矩形的面积最小. 稍微分析就会发现肯定是1*x的矩形最优,因为如果是2*x可以分成2个1*x. 那么我们先把矩形转转位置,使得n<=m,且(x,y)在左上角. 矩形内没有坏点,显然方案是(n+1)/2 我们画个图,黑色的那个是坏

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

数学 HDOJ 5301 Buildings

题目传送门 1 /* 2 题意:n*m列的矩阵,删除一个格子x,y.用矩形来填充矩阵.且矩形至少有一边是在矩阵的边缘上. 3 求满足条件的矩形填充方式中面积最大的矩形,要使得该最大矩形的面积最小. 4 分析:任何矩形都可以分为宽度为1的小矩形,所以只考虑矩形的可以的最小长度即可. 5 讨论方法:这里 (我不会...) 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 using

hdoj 5301 Buildings

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <algorithm> 5 using namespace std; 6 int n,m,x,y,s,l; 7 int main() 8 { 9 while(~scanf("%d%d%d%d&qu

hdu 4296 Buildings(贪婪)

主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the st

hdu 4296 Buildings 贪心算法 今日首A 详细解析 ,有些数据类型最好用long long

Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2278    Accepted Submission(s): 870 Problem Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr

HDU 5301(Buildings-贪心构造)

Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2210    Accepted Submission(s): 624 Problem Description Your current task is to make a ground plan for a residential building located