HDU 5538 House Building——思路题

来源:互联网 发布:java char 编辑:程序博客网 时间:2024/05/29 23:22
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int MAXN = 100;const int dx[] = {0, 0, -1, 1};const int dy[] = {-1, 1, 0, 0};int T, N, M, a[MAXN][MAXN];int main() {    scanf("%d", &T);    for (int kase = 1; kase <= T; kase++) {        scanf("%d %d", &N, &M);        memset(a, 0, sizeof(a));        int ans1 = 0, ans2 = 0;        for (int i = 1; i <= N; i++) {            for (int j = 1; j <= M; j++) {                scanf("%d", &a[i][j]);                if (a[i][j]) ans1++;            }        }        for (int i = 1; i <= N; i++) {            for (int j = 1; j <= M; j++) {                for (int k = 0; k < 4; k++) {                    int x = i + dx[k], y = j + dy[k];                    if (a[x][y] < a[i][j]) ans1 += a[i][j] - a[x][y];                }            }        }        printf("%d\n", ans1 + ans2);    }    return 0;}

原创粉丝点击