标签:
这个题好像很有趣的样子。
题目分析:
算法流程:
一些细节:
时间复杂度:$O(T)$,空间复杂度:$O(1)$。
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 5 const int Fx[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; 6 int n, m, x, y; 7 8 inline int Calc(int tx, int ty, int k) 9 { 10 int Min = min(n, m); 11 for (int i = 0; i < 4; i ++) 12 { 13 if (k == i) continue ; 14 if (i == 0) Min = min(Min, n + 1 - tx); 15 if (i == 1) Min = min(Min, tx); 16 if (i == 2) Min = min(Min, m + 1 - ty); 17 if (i == 3) Min = min(Min, ty); 18 } 19 return Min; 20 } 21 22 inline int Solve() 23 { 24 if (n == m && (n & 1) && x == y && (x * 2 - 1 == n)) 25 return n - 1 >> 1; 26 int ans = min(n, m) + 1 >> 1; 27 for (int k = 0; k < 4; k ++) 28 { 29 int tx = x + Fx[k][0], ty = y + Fx[k][1]; 30 if (tx && ty && tx <= n && ty <= m) 31 ans = max(ans, Calc(tx, ty, k ^ 1)); 32 } 33 return ans; 34 } 35 36 int main() 37 { 38 while (scanf("%d%d%d%d", &n, &m, &x, &y) == 4) 39 printf("%d\n", Solve()); 40 41 return 0; 42 }
标签:
原文地址:http://www.cnblogs.com/gromah/p/4908227.html