题目地址:http://codeforces.com/contest/984/problem/B

 

题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的。

 

题解:把输入的地图转换为数字格式,自己重新按炸弹绘制一幅图,对比一下。

 

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
const int inf = 0x3f3f3f3f;
int main()
{
    int n, m;
    int map[150][150], co[150][150] = {0};
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
    {
        getchar();
        for (int j = 0; j < m; j++)
        {
            char cell;
            scanf("%c", &cell);
            if (cell == '*')
            {
                map[i][j] = 10;
                co[i][j] = 10;
                co[i - 1][j - 1]++; co[i - 1][j]++; co[i - 1][j + 1]++;
                co[i][j - 1]++; co[i][j + 1]++;
                co[i + 1][j - 1]++; co[i + 1][j]++; co[i + 1][j + 1]++;
            }
            else if (cell == '.')
                map[i][j] = 0;
            else
                map[i][j] = cell - '0';
        }
    }
    int flag = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (map[i][j] != co[i][j]&&co[i][j]<=8)
            {
                flag = 0;
                goto x;
            }
        }
    }
x:
    if (flag == 0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}