本文主要是介绍hdu 4500 小Q系列故事――�丝的逆袭(检索),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
解题思路:遍历啊,这么水的题目还来看题解!
#include<stdio.h>
#include<string.h>
#define N 25int map[N][N];
int n, m, x, y, max;
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int judge(int a, int b){int sum = 0;if (map[a][b] > 0){for (int i = 0; i < 4; i++){int p = a + dir[i][0], q = b + dir[i][1];if (p < 0 || p >= n) continue;if (q < 0 || q >= m) continue;sum = sum - map[p][q];}}else{for (int i = 0; i < 4; i++){int p = a + dir[i][0], q = b + dir[i][1];if (p < 0 || p >= n) continue;if (q < 0 || q >= m) continue;sum = sum + map[p][q];}}return sum;
}int main(){while (scanf("%d%d", &n, &m), n || m){// Init.memset(map, 0, sizeof(map));max = 0;// Read.for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)scanf("%d", &map[i][j]); // Find.for (int i = 0; i < n; i++)for (int j = 0; j < m; j++){int k = judge(i, j);if (k > max){max = k;x = i;y = j;}}// Printf.printf("%d %d %d\n", x + 1, y + 1, max);}return 0;}
这篇关于hdu 4500 小Q系列故事――�丝的逆袭(检索)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!