Buildings
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3672 Accepted Submission(s): 1033
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.
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.
![](https://i-blog.csdnimg.cn/blog_migrate/b16f0af269cd055120660f793d08744c.jpeg)
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).
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
题意:要建一个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>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=200010;
const ll mo=1e9+7;
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);
// if(flag) puts("YES"); else puts("NO");
}
return 0;
}