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

hdu 5301 Buildings

2015-08-14 10:07 295 查看
题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5301

解题思路:

官方题解:

AC代码:





按照官方题解if顺序,很遗憾,并没有ac。。。后来看了别人的题解。。。才明白只能是:

if(n % 2 && n == m && x == y && x == (n+1)/2)
            answer = n / 2;
        else if(x == ans || x == ans + 1 || y == 1 || y == m)
            answer = ans;
        else if(min(left, right) > ans)
            answer= min(max(up,down),min(left,right));
        else
            answer = ans;


AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int main(){
int n,m,x,y;
while(scanf("%d%d%d%d",&n,&m,&x,&y) != EOF){
if(n > m){
swap(n,m);
swap(x,y);
} //n<=m
int ans = (n + 1) / 2,answer;
int left = y,right = m - y+1;
int up = x-1,down = n-x;
if(n % 2 && n == m && x == y && x == (n+1)/2) answer = n / 2; else if(x == ans || x == ans + 1 || y == 1 || y == m) answer = ans; else if(min(left, right) > ans) answer= min(max(up,down),min(left,right)); else answer = ans;
printf("%d\n",answer);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: