原题链接:http://codeforces.com/contest/984/problem/B

Minesweeper

One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.

Alex has grown up since then, so he easily wins the most difficult levels. This quickly bored him, and he thought: what if the computer gave him invalid fields in the childhood and Alex could not win because of it?

He needs your help to check it.

A Minesweeper field is a rectangle n×mn×mn×m, where each cell is either empty, or contains a digit from 111 to 8" role="presentation" style="position: relative;">888, or a bomb. The field is valid if for each cell:

if there is a digit kkk in the cell, then exactly k" role="presentation" style="position: relative;">kkk neighboring cells have bombs.
if the cell is empty, then all neighboring cells have no bombs.

Two cells are neighbors if they have a common side or a corner (i. e. a cell has at most 888 neighboring cells).

Input

The first line contains two integers n" role="presentation" style="position: relative;">nnn and m(1≤n,m≤100)m(1≤n,m≤100)m (1≤n,m≤100) — the sizes of the field.

The next nnn lines contain the description of the field. Each line contains m" role="presentation" style="position: relative;">mmm characters, each of them is “.” (if this cell is empty), “*” (if there is bomb in this cell), or a digit from 111 to 8" role="presentation" style="position: relative;">888, inclusive.

Output

Print “YES”, if the field is valid and “NO” otherwise.

You can choose the case (lower or upper) for each letter arbitrarily.

Examples
input

3 3
111
1*1
111

output

YES

input

2 4
..
1211

output

NO

Note

In the second example the answer is “NO” because, if the positions of the bombs are preserved, the first line of the field should be *2*1.

You can read more about Minesweeper in Wikipedia’s article.

题解

小小的模拟了解一下。

代码
#include<bits/stdc++.h>
using namespace std;
const int M=105;
int c1[]={0,1,1, 1, 0,-1,-1,-1};
int c2[]={1,1,0,-1,-1,-1, 0, 1};
int mmp[M][M],n,m;
char ch[M];
void in()
{scanf("%d%d",&n,&m);for(int i=1;i<=n;++i){scanf("%s",ch+1);for(int j=1;j<=m;++j)if(isdigit(ch[j]))mmp[i][j]=ch[j]-'0';else if(ch[j]=='*')mmp[i][j]=100;}
}
void ac()
{for(int i=1;i<=n;++i)for(int j=1,cot;j<=m;++j){cot=0;if(mmp[i][j]<9){for(int k=0;k<8;++k)if(mmp[i+c1[k]][j+c2[k]]>9)++cot;if(cot!=mmp[i][j])puts("NO"),exit(0);}}puts("YES");
}
int main(){in();ac();}

CF984B Minesweeper相关推荐

  1. python扫雷 广度优先_Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper)...

    Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary Tre ...

  2. python3扫雷代码_GitHub - pantaduce/minesweeper: Python代码编写的扫雷游戏

    Minesweeper(扫雷) 这是一个由Python编写的扫雷游戏,基于tkinter/Tkinter开发,支持python2和python3. 功能 概述 基本功能:左键扫雷,右键标记 记录游戏步 ...

  3. java版扫雷下载_Java 实现扫雷游戏(MineSweeper)

    package com.kerence.mine.data_structure; /** * 雷块类的属性和操作 * * @download:http://www.codefans.net * @au ...

  4. UVA10189 Minesweeper【Ad Hoc】

    Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating Sys ...

  5. 蓝桥杯 提高题 Minesweeper

    蓝桥杯 提高题 Minesweeper 题目描述 Minesweeper Have you ever played Minesweeper? This cute little game comes w ...

  6. 网络验证Minesweeper使用 学习(1)

    Minesweeper使用之BGP测试 学习 一.BGP1 1.导入BGP1的网络. init-testrig /home/yahui/Desktop/batfish-abstraction-fixe ...

  7. MInesweeper

    MInesweeper 输入: 4 4 *... .... .*.. .... 3 5 **... ..... .*... 0 0 输出: Field #1: *100 2210 1*10 1110F ...

  8. BUUCTF Reverse/Ultimate Minesweeper

    BUUCTF Reverse/Ultimate Minesweeper 先看文件信息,没有加壳,且为net编写的程序 运行是一个扫雷游戏,只要点错一个就会自动退出(左上角显示的是雷的数目,一共有897 ...

  9. 问题 1096: Minesweeper

    原题目链接-蓝桥杯练习题目 问题 1096: Minesweeper 时间限制: 1Sec 内存限制: 64MB 提交: 2759 解决: 1128 题目描述 Minesweeper Have you ...

  10. UVA 10189 Minesweeper

    UVA 10189 Minesweeper Have you ever played Minesweeper? It's a cute little game which comes within a ...

最新文章

  1. 当博导10年,一博士生跟了我7年,我是悲喜交加...
  2. 深入浅出linux三剑客之sed必杀技一例
  3. android studio运行时报错the selected device is incompatible
  4. 一个可以显示具体时间的日历控件应用
  5. php调用dll函数,[转载]matlab调用DLL中的函数
  6. LAMPLNMP自动化安装脚本
  7. UNIX(多线程):21---线程池实现原理
  8. 用复制mysql/data 文件夹 下面的数据库的形式来复制数据库出现的问题
  9. oc 画一个圆弧_UG建模一个蜗杆的方法,纯手工建模无插件
  10. 策略模式(headfirst设计模式学习笔记)
  11. 算法-冒泡排序和快速排序
  12. java生成iso9660工具_基于数据库的代码自动生成工具,生成JavaBean、生成数据库文档、生成前后端代码等(TableGo v7.0.0版)...
  13. git的丰富实用经验
  14. python判断一个数是否为水仙花数_Python判断一个三位数是否为水仙花数的示例
  15. 三菱f800变频器 频率设定_三菱F800变频器调试参数总结
  16. 做了5年Android开发,混吃等死的日子才是我人生最辛苦的日子!
  17. 数据库的三级封锁协议
  18. 自定义注解(中英文字段名字映射)
  19. kafka设置起止时间消费消息
  20. 【OpenWRT】 Chaos Calmer 15.05 编译

热门文章

  1. php背景图片居中对齐命令,css怎么设置背景图片自适应居中
  2. 360修复高危漏洞可以修复吗_大理石刮痕可以修复吗?如何修复?
  3. Linux防火墙iptables配置详解
  4. Android studio 报错Failed to open zip file解决方法
  5. 网站搭建 (第03天) 分页功能
  6. Liferay 6.2 改造系列之十三:修改用户编辑页面表单内容
  7. HP MSA2312 ERROR
  8. sicily 1295. 负权数
  9. Linux上安装GCC编译器过程实录
  10. JVM监控及诊断工具命令行篇之jstatd