TYUT-codeforce-----Minesweeper

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×m, where each cell is either empty, or contains a digit from 1 to 8, or a bomb. The field is valid if for each cell:

if there is a digit k in the cell, then exactly k 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 8 neighboring cells).

Input
The first line contains two integers n and m (1≤n,m≤100) — the sizes of the field.

The next n lines contain the description of the field. Each line contains m characters, each of them is “.” (if this cell is empty), “*” (if there is bomb in this cell), or a digit from 1 to 8, 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 21.

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

题目大意:给定由n行m列的扫雷元素,判断对应数字的8个范围内的雷数量是否和该数字一致。‘*’表示雷,‘.'表示0,其余数字用字符’1‘到’8‘表示。
思路:构建两个数组a和b,a数组读取扫雷,b数组元素全部初始化为’0‘,把a中的雷的元素映射到b上。根据b数组重新模拟一次,判断a,b数组最后是否相等即可。

AC的C++代码如下:

#include<iostream>
using namespace std;
char a[105][105], b[105][105];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)     //初始化b数组
		for (int r = 1; r <= m; r++)
			b[i][r] = '0';            
	for (int i = 1; i <= n; i++)     //读入a数组,并把a的雷映射到b
		for (int r = 1; r <= m; r++)
		{
			cin >> a[i][r];
			if (a[i][r] == '*')
				b[i][r] = a[i][r];
		}
	for(int i=1;i<=n;i++)            //使用b数组重新模拟一次所有的数字
		for (int r = 1; r <= m; r++)
		{
			if (b[i][r] == '*')
			{
				if (b[i][r - 1] != '*') b[i][r - 1]++;
				if (b[i - 1][r] != '*') b[i - 1][r]++;
				if (b[i + 1][r] != '*') b[i + 1][r]++;
				if (b[i][r + 1] != '*') b[i][r + 1]++;
				if (b[i + 1][r + 1] != '*') b[i + 1][r + 1]++;
				if (b[i - 1][r - 1] != '*') b[i - 1][r - 1]++;
				if (b[i + 1][r - 1] != '*') b[i + 1][r - 1]++;
				if (b[i - 1][r + 1] != '*') b[i - 1][r + 1]++;
			}
		}
	for (int i = 1; i <= n; i++)      //把’0‘元素改成'.'
		for (int r = 1; r <= m; r++)
			if (b[i][r] == '0')
				b[i][r] = '.';
	int flag = 1;                     //判断a,b两数组是否完全一致
	for(int i=1;i<=n;i++)
		for(int r=1;r<=m;r++)
			if (a[i][r] != b[i][r])
			{
				flag = 0;
				break;
			}
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;
}
当您在Linux系统中遇到“-bash: npm: command not found”这样的错误时,意味着npm(Node.js的包管理器)没有被正确安装,或者其可执行文件没有被添加到系统的PATH环境变量中。要解决这个问题,您可以按照以下步骤操作: 1. 确认Node.js是否已经安装:因为npm是随Node.js一起安装的,所以首先需要确认Node.js是否已经安装在您的系统上。可以通过运行`node -v`来检查Node.js的版本。 2. 如果没有安装Node.js,您需要下载并安装它。您可以从Node.js官网(https://nodejs.org/)下载适合您操作系统的安装包进行安装。 3. 安装Node.js后,npm通常会自动安装。您可以运行`npm -v`来检查npm是否已经正确安装。 4. 如果npm安装了但仍然提示命令未找到,可能是因为npm的安装路径没有被添加到PATH环境变量中。您可以通过以下命令来查看当前的PATH: ``` echo $PATH ``` 然后将npm的安装路径添加到PATH中。通常npm的安装路径是`/usr/local/bin`,您可以使用以下命令将其添加到PATH: ``` export PATH=$PATH:/usr/local/bin ``` 注意,这个改变只是临时的,要永久更改PATH,您需要将上面的命令添加到您的shell配置文件中,比如`~/.bashrc`或`~/.profile`。 5. 在某些情况下,如果npm是通过特定方式安装的,比如使用`nvm`(Node Version Manager)安装Node.js和npm,那么npm的路径可能会有所不同。您需要找到正确的npm可执行文件路径并添加到PATH中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值