zoukankan      html  css  js  c++  java
  • Codeforces Round #483 (Div. 2) B. Minesweeper

    题目地址: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
    ");
        else
            printf("YES
    ");
        return 0;
    }
  • 相关阅读:
    [51nod] 1301 集合异或和
    [BZOJ] 1088: [SCOI2005]扫雷Mine
    [LUOGU] P4251 [SCOI2015]小凸玩矩阵
    8.21模拟赛
    [BZOJ] 3163: [Heoi2013]Eden的新背包问题
    [BZOJ] 1001: [BeiJing2006]狼抓兔子
    【NOIP2017提高A组冲刺11.8】好文章
    [BZOJ] 1520: [POI2006]Szk-Schools
    [BZOJ] 1877: [SDOI2009]晨跑
    day23(事务管理)
  • 原文地址:https://www.cnblogs.com/Tangent-1231/p/9076578.html
Copyright © 2011-2022 走看看