标签:
Description
Input
Output
Sample Input
Sample Output
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.
注释在代码里。
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int n,m,x,y,ans; int main(){ //freopen("in.txt","r",stdin); while(~scanf("%d%d%d%d", &n, &m, &x, &y)){ if(n>m) swap(n,m),swap(x,y);//统一处理 ans=(n+1)/2;//短边的一半 int t1=max(x-1,n-x),t2=min(y,m-y+1); if(ans<t2&&x-1!=n-x) ans=min(t1,t2); //如果x-1!=n-x,则t1>=ans,且此时若ans<t2,则说明纵向放置欠缺部分无法以横向放置替代 //因此,换成t1,则可以补足纵向放置欠缺,换成t2,则可以以横向放置替代纵向,取较小者 if(n==m&&x==y&&(x*2-1==n)) ans=(n-1)/2; //如果在正中间,需特殊判定。 printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/names-yc/p/4703029.html