您的位置:首页 > 产品设计 > UI/UE

hdoj-5301-Buildings

2016-05-09 15:02 429 查看
[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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).

[align=left]Output[/align]
For each testcase, print only one interger, representing the answer.

[align=left]Sample Input[/align]

2 3 2 2
3 3 1 1


[align=left]Sample Output[/align]

1
2

Hint
Case 1 :



You can split the floor into five $1 \times 1$ apartments. The answer is 1.

Case 2:



You can split the floor into three $2 \times 1$ apartments and two $1\times 1$ apartments. The answer is 2.



If you want to split the floor into eight $1 \times 1$ apartments, it will be unacceptable because the apartment located on (2,2) can't have windows.


[align=left]Author[/align]
XJZX

[align=left]Source[/align]
2015 Multi-University Training Contest 2

对于每一个黑格子,求出它上下左右四个方格到三个方向的值,然后可以求出四个最小值来,四个最小值里面要找个最大值,再与n,m边的一半作为比较,不能小于他们的一半。

这道题在训练的时候并没有做出来,最后看到别人的题解才知道做的,说这个题目有个一wa点就是当那个黑格子在最中间时要单独拿出来讨论

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,m,x,y;
while(cin>>n>>m>>x>>y)
{
int answer=0;
if(n==m&&n%2!=0&&x==y&&x==(n+1)/2)
{
if(n==m)  answer=(n+1)/2-1;
}
else
{
if(n>m)  swap(n,m),swap(x,y);
int ans=0;
int nut=0;
ans=(n+1)/2;
nut=(m+1)/2;
int a=0,b=0,c=0,d=0;
a=min(y,min(x-1,m-y+1));
b=min(y-1,min(x,n-x+1));
c=min(n-x,min(y,m-y+1));
d=min(n-x+1,min(x,m-y));
int sum=0;
sum=max(a,max(b,max(c,d)));
answer=max(sum,min(ans,nut));
}
cout<<answer<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: