HDU 5538 House Building——思路题
#include #include #include #include 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;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~