HZAU 1002 Mine Sweeping Game

模拟就好
原题

#include <cstdio>
#include <cstring>
using namespace std;
const int MAX_N = 10 + 9;
const int MAX_M = 10 + 9;
void solve()
{
  int a[MAX_N][MAX_M];
  memset(a, 0, sizeof(a));
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--;
    y--;
    for (int dx = -1; dx <= 1; dx++)
      for (int dy = -1; dy <= 1; dy++) {
        int xx = x + dx;
        int yy = y + dy;
        if (xx < 0 || xx >= n || yy < 0 || yy >= m || a[xx][yy] == -1) continue;
          a[xx][yy]++;
      }
    a[x][y] = -1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == -1) {
        putchar('M');
        continue;
      }
      if (a[i][j] == 0) {
        putchar('.');
        continue;
      }
      printf("%d", a[i][j]);
    }
    putchar('\n');
  }
}
int main()
{
// freopen("input.txt", "r", stdin);
  int t;
  scanf("%d", &t);
  solve();
  for (int i = 1; i < t; i++) {
    putchar('\n');
    solve();
  }
}

你可能感兴趣的:(HZAU 1002 Mine Sweeping Game)