hdu 5301 Buildings

来源:互联网 发布:静态路由协议端口号 编辑:程序博客网 时间:2024/05/16 09:41

题解 && 总结:

1.检测全面思考问题的能力

2.以后再碰到这样的问题,在纸上清楚地写出所有的情况,做到不重不漏

3.一道题目,如果连续三次没有AC便放手做其他的题目,不再纠结,争取平时做题也做到1A

4.不轻视简单的问题,认真对待每一个问题

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;#define MAXN 10000int n,m,x,y;int solve(){    if(n == m && (n & 1) && (n + 1) / 2 == x && x == y)        return n / 2;    if(m == 1 || n == 1)return 1;    if(x > n / 2)x = n - x + 1;    if(y > m / 2)y = m - y + 1;    int ans1 = min(max(x,n - x),max(y,m - y));    int ans2 = min(max(x,(m + 1) / 2),max(y,(n + 1) / 2));    int ans3 = max(x - 1,max(m - y,(m + 1) / 2));    int ans4 = max(y - 1,max(n - x,(n + 1) / 2));    return min(min(ans1,ans2),min(ans3,ans4));}int main(){    while(cin >> n >> m >> x >> y)    {        int ans = solve();        cout << ans << endl;    }}


0 0
原创粉丝点击