标签:

2 3 2 2 3 3 1 1
1 2HintCase 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.
对于每一个黑格子,求出它上下左右四个方格到三个方向的值,然后可以求出四个最小值来,四个最小值里面要找个最大值,再与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;
} 标签:
原文地址:http://blog.csdn.net/ypopstar/article/details/51353132