CF984B Minesweeper
原题链接: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相关推荐
- python扫雷 广度优先_Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper)...
Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary Tre ...
- python3扫雷代码_GitHub - pantaduce/minesweeper: Python代码编写的扫雷游戏
Minesweeper(扫雷) 这是一个由Python编写的扫雷游戏,基于tkinter/Tkinter开发,支持python2和python3. 功能 概述 基本功能:左键扫雷,右键标记 记录游戏步 ...
- java版扫雷下载_Java 实现扫雷游戏(MineSweeper)
package com.kerence.mine.data_structure; /** * 雷块类的属性和操作 * * @download:http://www.codefans.net * @au ...
- UVA10189 Minesweeper【Ad Hoc】
Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating Sys ...
- 蓝桥杯 提高题 Minesweeper
蓝桥杯 提高题 Minesweeper 题目描述 Minesweeper Have you ever played Minesweeper? This cute little game comes w ...
- 网络验证Minesweeper使用 学习(1)
Minesweeper使用之BGP测试 学习 一.BGP1 1.导入BGP1的网络. init-testrig /home/yahui/Desktop/batfish-abstraction-fixe ...
- MInesweeper
MInesweeper 输入: 4 4 *... .... .*.. .... 3 5 **... ..... .*... 0 0 输出: Field #1: *100 2210 1*10 1110F ...
- BUUCTF Reverse/Ultimate Minesweeper
BUUCTF Reverse/Ultimate Minesweeper 先看文件信息,没有加壳,且为net编写的程序 运行是一个扫雷游戏,只要点错一个就会自动退出(左上角显示的是雷的数目,一共有897 ...
- 问题 1096: Minesweeper
原题目链接-蓝桥杯练习题目 问题 1096: Minesweeper 时间限制: 1Sec 内存限制: 64MB 提交: 2759 解决: 1128 题目描述 Minesweeper Have you ...
- UVA 10189 Minesweeper
UVA 10189 Minesweeper Have you ever played Minesweeper? It's a cute little game which comes within a ...
最新文章
- 当博导10年,一博士生跟了我7年,我是悲喜交加...
- 深入浅出linux三剑客之sed必杀技一例
- android studio运行时报错the selected device is incompatible
- 一个可以显示具体时间的日历控件应用
- php调用dll函数,[转载]matlab调用DLL中的函数
- LAMPLNMP自动化安装脚本
- UNIX(多线程):21---线程池实现原理
- 用复制mysql/data 文件夹 下面的数据库的形式来复制数据库出现的问题
- oc 画一个圆弧_UG建模一个蜗杆的方法,纯手工建模无插件
- 策略模式(headfirst设计模式学习笔记)
- 算法-冒泡排序和快速排序
- java生成iso9660工具_基于数据库的代码自动生成工具,生成JavaBean、生成数据库文档、生成前后端代码等(TableGo v7.0.0版)...
- git的丰富实用经验
- python判断一个数是否为水仙花数_Python判断一个三位数是否为水仙花数的示例
- 三菱f800变频器 频率设定_三菱F800变频器调试参数总结
- 做了5年Android开发,混吃等死的日子才是我人生最辛苦的日子!
- 数据库的三级封锁协议
- 自定义注解(中英文字段名字映射)
- kafka设置起止时间消费消息
- 【OpenWRT】 Chaos Calmer 15.05 编译