Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4500
AC code:
1 # include <math. h> 2 # include <stdio. h> 3 4 # define maxn 21 5 6 int n, m, Ki [maxn] [maxn]; 7 int wi [4] = {0, 1, 0, -1}, 8 WJ [4] = {-1, 0, 1, 0}; 9 10 bool input () {11 scanf ("% d ", & N, & M); 12 if (n = 0 & M = 0) {13 return false; 14} 15 for (INT I = 1; I <= N; ++ I) {16 for (Int J = 1; j <= m; ++ J) {17 scanf ("% d ", & Ki [I] [J]); 18} 19} 20 return true; 21} 22 23 void solve () {24 int Bi = 0, bj = 0, BK = 0; 25 // The optimal value for the coordinates of the coordinate column of the row to make the high score 26 for (INT I = 1; I <= N; ++ I) {27 for (Int J = 1; j <= m; ++ J) {28 int kcore = 0; 29 30 for (int K = 0; k <4; + + k) {31 // 32 int Ti = I + wi [K], TJ = J + WJ [k] at the top, bottom, left, right, left, right, and right; 33 if (1 <= Ti & Ti <= N & 1 <= TJ & TJ <= m) {34 if (KI [I] [J] * ki [Ti] [TJ] <0) {35 kcore + = ABS (KI [Ti] [TJ]); 36} else {37 kcore-= ABS (KI [Ti] [TJ]); 38} 39} 40} 41 42 if (kcore> BK) {43 // update the optimal value 44 BK = kcore; 45 Bi = I; 46 bj = J; 47} 48} 49} 50 printf ("% d \ n", Bi, BJ, BK); 51} 52 53 int main () {54 while (input () {55 solve (); 56} 57 Return 0; 58}
The story of the HDU 4500 Q Series-the counterattack of diaosi (simple question)