蓝桥杯 提高题 Minesweeper

题目描述

Minesweeper Have you ever played Minesweeper? This cute little game comes with a certain operating system whose name we can’t remember. The goal of the game is to find where all the mines are located within a M x N field. The game shows a number in a square which tells you how many mines there are adjacent to that square. Each square has at most eight adjacent squares. The 4 x 4 field on the left contains two mines, each represented by a ′∗′'*'′∗′ character. If we represent the same field by the hint numbers described above, we end up with the field on the right: ∗........∗......∗10022101∗101110*... .... .*.. .... *100 2210 1*10 1110∗........∗......∗10022101∗101110

输入

The input will consist of an arbitrary number of fields. The first line of each field contains two integers n and m (0<n,m≤100)( 0 < n, m\leq100)(0<n,m≤100) which stand for the number of lines and columns of the field, respectively. Each of the next n lines contains exactly m characters, representing the field. Safe squares are denoted by ′.′'.'′.′and mine squares by ′∗′'*'′∗′ both without the quotes. The first field line where n = m = 0 represents the end of input and should not be processed.

输出

For each field, print the message Field #x: on a line alone, where x stands for the number of the field starting from 1. The next n lines should contain the field with the ``.’’ characters replaced by the number of mines adjacent to that square. There must be an empty line between field outputs.

样例输入

4 4
*...
....
.*..
....
3 5
**...
.....
.*...
0 0

样例输出

Field #1:
*100
2210
1*10
1110Field #2:
**100
33200
1*100

简单BFS,注意输出格式即可:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100][100];
int num[100][100],n,m;
int step[8][2]={0,1, 0,-1, 1,0 ,-1,0, 1,1, -1,1, 1,-1, -1,-1};void bfs(int x,int y){int xx,yy;for(int i=0;i<8;i++){xx=x+step[i][0];yy=y+step[i][1];if(xx>=0 && xx<4 && yy>=0 && yy<4 && s[xx][yy]!='*') num[xx][yy]++;}
}int main() {int id=0;while(cin>>n>>m){id++;if(n==0 && m==0) break;for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>s[i][j];}}fill(num[0],num[0]+100*100,0);for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(s[i][j]=='*') bfs(i,j);}}printf("Field #%d:\n",id);for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(s[i][j]=='*') cout<<"*";else cout<<num[i][j];}puts("");}puts("");}
}

蓝桥杯 提高题 Minesweeper相关推荐

  1. 蓝桥杯 提高题 母牛的故事

    蓝桥杯 提高题 母牛的故事 题目描述 有一头母牛,它每年年初生一头小母牛.每头小母牛从第四个年头开始,每年年初也生一头小母牛.请编程实现在第n年的时候,共有多少头母牛? 输入 输入数据由多个测试实例组 ...

  2. 【蓝桥杯真题】16天冲刺 Python

    距离比赛很快了,希望和我一起准备的PY党能更加熟练的掌握Python! 1.距离和(模拟赛填空题) 问题描述: 两个字母之间的距离定义为它们在字母表中位置的距离.例如 A和 C 的距离为 2,L 和  ...

  3. 第九届蓝桥杯真题解析JavaC组

    第九届蓝桥杯真题解析JavaC组 文章目录 ***第九届蓝桥杯真题解析JavaC组*** 前言 A.哪天回家 B.猴子分香蕉 C.字母阵列 D.第几个幸运数 E.书号验证 F.打印大X G.缩位求和 ...

  4. 2019蓝桥杯每周一题第二周之Mineweep(扫雷)

    2019蓝桥杯每周一题第二周之Mineweep(扫雷) 写在开头: 写这个题的时候真的是一次次的纠错,题不难,里面的逻辑关系有复杂,每一次都以为会运行正确了,结果又一个小地方出错,写了一上午还是有问题 ...

  5. python解答蓝桥杯真题2 猜年龄 美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学。他曾在19351936年应邀来中国清华大学讲学。。。

    python解答蓝桥杯真题2 猜年龄 美国数学家维纳(N.Wiener)智力早熟,11岁就上了大学.他曾在1935~1936年应邀来中国清华大学讲学... 问题描述 全排列模板: 美国数学家维纳(N. ...

  6. 第十届蓝桥杯真题题解

    目录 一.组队(DFS) 二.年号字串(进制转换) 三.数列求值 四.数的分解 五.迷宫(BFS) 六.特别数的和(暴力) 七.完全二叉树的权值 一.组队(DFS) 题目描述 本题为填空题,只需要算出 ...

  7. 第五届蓝桥杯真题解析【JavaC组】

    第五届蓝桥杯真题解析[JavaC组] 业精于勤,荒于嬉:行成于思,毁于随.--韩愈 文章目录 ***第五届蓝桥杯真题解析[JavaC组]*** 前言 A:猜年龄 B:等额本金 C:猜字母 D:大衍数列 ...

  8. 蓝桥杯真题:三羊献瑞

    蓝桥杯真题:三羊献瑞 观查下面的加法算式: 其中相同的汉字代表相同的数字,不同的汉字代表不同的数字. 请你填写"三羊献瑞"所代表的4位数字(答案唯一),不要填写任何多余内容. 分析 ...

  9. 第十二届蓝桥杯D题 货物摆放

    第十二届蓝桥杯D题 货物摆放 题意[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 这里我们会发现他的方案数就是所有因数的组合数乘积等于n; #include<iostrea ...

最新文章

  1. Eclipse 3.5 Classic+Tomcat 6.0+MySql 5.5搭建java web开发环境
  2. 操作系统:了解一下磁盘结构
  3. Video Question Answering综述
  4. sketchup 图片转模型_你应该知道的那些 Sketchup 实用快捷键和使用技巧!
  5. VTK:图片之ImageLaplacian
  6. k8s 安装nfs_K8s--06 K8s数据持久化
  7. SQL优化的思路及基本原则(mysql)
  8. python中文版软件下载-Python IDLE(Python集成开发环境)v3.7中文版
  9. winrar注册码激活码
  10. Juce-强大的开源类库
  11. 空间索引之网格与四叉树
  12. msxml6_x86.msi和msxml6_ia64.msi和msxml6_x64.msi的选择
  13. html怎么改变图片整体大小,html怎么改变图片大小
  14. HTML——HTML中的特殊符号
  15. 统计文件中元音字母的数量
  16. Move语言:我眼中的 Libra 最大亮点
  17. 如何使用HomePod和Apple TV 4K设置家庭影院音频?
  18. NTCUTTER BD-1002013年新包装通知
  19. 小程序接入h5页面_h5页面和小程序交互
  20. r语言中trifit怎么用_用R语言分析我的fitbit计步数据

热门文章

  1. 【和77】火车到底能不能当出租车开呢?(温微观察13-7)
  2. consul:健康检查
  3. ISO8601时间格式的转换
  4. c4d问题一:如何将坐标轴对齐到模型的地面中间处,也就是归零到世界坐标轴中心原点处,问题二:如何把模型刚好对齐到地面上
  5. android 获取sd卡目录失败_Android正确获取SD卡目录及使用SD卡目录
  6. 将.qsv格式视频转为.mp4视频
  7. 【XShell | Xftp】解决Xshell强制升级
  8. [Unity3D]Unity3D游戏开发之Unity与Android交互调用研究
  9. Kies Air连接电脑传文件挺好用的 不用连数据线
  10. 分享78个JS相册代码,总有一款适合您