题意:

给出一个矩阵,如果一个格子是数字,那么与这个格子相邻的格子中有炸弹的数量必须等于这个格子中的数字;

如果一个格子是空地,那么这个格子的所有相邻的格子中就不能有炸弹。

判断这个矩阵是否合法。

思路:

暴力枚举即可,不过空地那里要注意,相邻的是数字也可以。

代码:

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <ctype.h>
using namespace std;
const int N = ;
char mp[N][N];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for (int i = ;i < n;i++) scanf("%s",mp[i]);
bool f = ;
for (int i = ;i < n;i++)
{
for (int j = ;j < m;j++)
{
if (mp[i][j] >= '' && mp[i][j] <= '')
{
int t = mp[i][j] - '';
int cnt = ;
for (int x = -;x <= ;x++)
{
for (int y = -;y <= ;y++)
{
if (x == && y == ) continue;
int dx = i + x,dy = j + y;
if (dx < || dx >= n) continue;
if (dy < || dy >= m) continue;
if (mp[dx][dy] == '*') cnt++;
}
}
if (cnt != t) f = ;
}
else if (mp[i][j] == '.')
{
int cnt1 = ,cnt2 = ;
for (int x = -;x <= ;x++)
{
for (int y = -;y <= ;y++)
{
if (x == && y == ) continue;
int dx = i + x,dy = j + y;
if (dx < || dx >= n) continue;
if (dy < || dy >= m) continue;
cnt1++;
if (mp[dx][dy] != '*') cnt2++;
}
}
if (cnt1 != cnt2) f = ;
}
}
}
if (f) puts("NO");
else puts("YES");
return ;
}

codeforces 984B Minesweeper的更多相关文章

  1. CodeForces 404D Minesweeper 1D (DP)

    题意:给定一个序列,*表示雷,1表示它旁边有一个雷,2表示它旁边有两个雷,0表示旁边没有雷,?表示未知,求有多少情况. 析:dp[i][j] 表示第 i 个放 j 状态,有多少种情况,然后很简单的DP ...

  2. Codeforces 404D Minesweeper 1D

    题意: 给定字符串,其中'*'表示地雷,'1'表示左/右边有一个地雷相邻,'2'表示左右两边均有地雷相邻,'0'表示左右均无地雷相邻,'?'表示待定,可填入0,1,2或者地雷,有多少种表示方法使字母串 ...

  3. 近期做的一些DP

    UVa 1625 color length https://blog.csdn.net/Dylan_Frank/article/details/52261424 https://www.cnblogs ...

  4. 【codeforces 404D】Minesweeper 1D

    [题目链接]:http://codeforces.com/problemset/problem/404/D [题意] 让你玩一个1维的扫雷游戏; 游戏的描述由数字0..2以及符号*表示; 分别表示这个 ...

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

    题目地址:http://codeforces.com/contest/984/problem/B 题目大意:扫雷游戏,给你一个n*m的地图,如果有炸弹,旁边的八个位置都会+1,问这幅图是不是正确的. ...

  6. codeforces Minesweeper 1D

    题意:就是挖地雷,给你一个字符串,‘*’代表地雷,‘1’代表在它的周围有1个地雷,‘2’代表在左右都有个地雷,‘?’代表不确定是不是地雷,可以是1,2,*,问你最后有几种方式确定所有的的地雷. 思路: ...

  7. Codeforces Round #483 (Div. 2) B题

    B. Minesweeper time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!]

    题目链接:http://codeforces.com/contest/984 A. Game time limit per test:2 seconds memory limit per test:5 ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. linux 修改密码命令

    1.passwd命令  脚本中语法:echo "password" | passwd testuser --stdin > /dev/null 2>&1 或(e ...

  2. linux strncpy()和strcat使用总结

    strcat原型:char *strcat(char *dest,const char *src); 把src所指字符串添加到dest结尾处(覆盖dest结尾处的'\0')并添加'\0'.src和de ...

  3. NOIP国王游戏

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  4. MongoDB pymongo模块

    安装pymongo模块 pip install pymongo 连接mongodb代码,生成pymongo对象,传入连接服务器相关参数 ip 端口 如果使用指定的账户登录,设置要登录的账户和密码,然后 ...

  5. Codeforces Round #FF (Div. 2) 题解

    比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit p ...

  6. vs 2017 集成python

    官网:https://docs.microsoft.com/en-us/visualstudio/python/installation

  7. 【开发者笔记】python中的类方法(@classmethod)和静态方法(@staticmethod)

    在java.c#等高级语言中我们用static来定义静态方法和静态变量,那么在python中如何定义静态方法和静态变量呢. python提供了@classmethod和@staticmethod来定义 ...

  8. Swagger Editor本地安装

    一:安装Node JS 二:下载源码swagger-editor源码,解压 下载地址:https://github.com/swagger-api/swagger-editor 三:在解压目录下运行进 ...

  9. 【LeetCode每天一题】Remove Nth Node From End of List(移除链表倒数第N个节点)

    Given a linked list, remove the n-th node from the end of list and return its head. Example:        ...

  10. SQL 、NoSQL数据库教程

    前言: 嗯,先说说数据库的分类吧,其实主要大的分类就是关系型数据库(SQL)和非关系型数据库(NoSQL); 实验楼上有常见的数据库教程,这里做一个整理,希望对你学习数据库方面的知识有所帮助: 关系型 ...