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;
    }
  • 相关阅读:
    函数指针
    动态内存
    char*和char[]的区别
    C语言基本数据类型大小
    html5新特性localStorage和sessionStorage
    Swoole实现h5版聊天室笔记
    php使用mysql之sql注入(功)
    Http协议工作特点和工作原理笔记
    原生js使用ajax
    php常用的几个预定义变量
  • 原文地址:https://www.cnblogs.com/Tangent-1231/p/9076578.html
Copyright © 2011-2022 走看看