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 , where each apartment is a smaller rectangle with dimensions located inside. For each apartment, its dimensions can be different from each other. The number and must be integers.
Additionally, the apartments must completely cover the floor without one square located on . The apartments must not intersect, but they can touch.
For this example, this is a sample of .
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 testcases.
For each testcase, only four space-separated integers, .
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
题意:要建一个n*m的大房子,其中有一个格子不能建房间。你要建若干个矩形的房间,并且每个矩形至少有一个边是房子的边界。求使面积最大的那个房间的面积最小的面积。
思路:
先考虑不能建房间的格子无影响的情况,答案是(min(m,n)+1)/2。
如果不能建房间的格子有好的影响,其实只有一种情况:n==m 且n、m为奇数且x、y就是中间的那个格子。
这种情况下答案为n/2。
如果不能建房间的格子有坏的影响,那就只会影响那一行或者那一列的房间。于是先固定n>m,这样只有第x行的格子受到影响,而且是(x,y)左右两边的格子中离左右边界最远的那个格子。于是我们枚举它向上、向下、向左或右建的最小面积。最后和(min(m,n)+1)/2取个最大值
扩展:
这种思维技巧题,如果要说扩展的话就是不太好想,感觉上有点类似于哪种铺地板的题目,不过不是很一样
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int n,m,k,x,y;
int a[maxn],sum[maxn];
int c[maxn],pos[maxn],l[maxn],r[maxn];
int ans,ct,cnt,tmp,flag;
char s[maxn];
int main()
{
while(scanf("%d%d%d%d",&n,&m,&x,&y)!=EOF)
{
ans=0;
flag=1;
if(n<m)
{
swap(n,m);
swap(x,y);
}
ans=(m+1)/2;
if((n&1)&&n==m&&x==y&&y==(m+1)/2)
ans=n/2;
else{
x=min(x,n-x+1);
y=max(y-1,m-y);
int aa=min(x,y);
ans=max(ans,aa);
}
printf("%d\n",ans);
}
return 0;
}