Codeforces Round #483 (Div. 2) B. Minesweeper

本文介绍Codeforces Round #483 (Div. 2) B题Minesweeper的解题思路与代码实现。该题要求验证给定地图是否符合扫雷规则,通过对比用户输入地图与自动生成的地图来判断正确性。

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\n");
    else
        printf("YES\n");
    return 0;
}

 

posted @ 2018-05-23 13:56 Tangent_1231 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值