原题 http://poj.org/problem?id=2612

题目:

Mine Sweeper
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6638 Accepted: 2564
Description

The game Minesweeper is played on an n by n grid. In this grid are hidden m mines, each at a distinct grid location. The player repeatedly touches grid positions. If a position with a mine is touched, the mine explodes and the player loses. If a positon not containing a mine is touched, an integer between 0 and 8 appears denoting the number of adjacent or diagonally adjacent grid positions that contain a mine. A sequence of moves in a partially played game is illustrated below.

Here, n is 8, m is 10, blank squares represent the integer 0, raised squares represent unplayed positions, and the figures resembling asterisks represent mines. The leftmost image represents the partially played game. From the first image to the second, the player has played two moves, each time choosing a safe grid position. From the second image to the third, the player is not so lucky; he chooses a position with a mine and therefore loses. The player wins if he continues to make safe moves until only m unplayed positions remain; these must necessarily contain the mines.

Your job is to read the information for a partially played game and to print the corresponding board.
Input

The first line of input contains a single postitive integer n <= 10. The next n lines represent the positions of the mines. Each line represents the contents of a row using n characters: a period indicates an unmined positon while an asterisk indicates a mined position. The next n lines are each n characters long: touched positions are denoted by an x, and untouched positions by a period. The sample input corresponds to the middle figure above.
Output

Your output should represent the board, with each position filled in appropriately. Positions that have been touched and do not contain a mine should contain an integer between 0 and 8. If a mine has been touched, all positions with a mine should contain an asterisk. All other positions should contain a period.
Sample Input

8
*..
……*.
….*…
……..
……..
…..*..
*..
…..*..
xxx…..
xxxx….
xxxx….
xxxxx…
xxxxx…
xxxxx…
xxx…..
xxxxx…
Sample Output

001…..
0013….
0001….
00011…
00001…
00123…
001…..
00123…

思路:

扫雷的玩法就是翻数寻雷,翻出来的数是1代表周围的八个格子有1个雷,2代表有2个,等等。
逆向思维的结果就是每个雷周围有8个1,当两个雷有相邻的时候,数字可以叠加。
简单的遍历就可以求出结果。不太清楚的可以去玩几把。
注意:点到雷的时候所有雷都是会显示的。

代码:

#include <iostream>
#include"string.h"
#include"cstdio"
#include"stdlib.h"
#include"algorithm"using namespace std;
typedef long long int lint;
const int bc=12;
char tu[bc][bc];
char flag[bc][bc];
char antu[bc][bc];
int ans[bc][bc];
int main()
{int n;while(scanf("%d",&n)!=EOF){getchar();for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){scanf("%c",&tu[i][j]);}getchar();}for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){scanf("%c",&flag[i][j]);}getchar();}memset(ans,0,sizeof(ans));for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){if(tu[i][j]=='*'){ans[i-1][j-1]++;ans[i-1][j]++;ans[i-1][j+1]++;ans[i][j-1]++;ans[i][j+1]++;ans[i+1][j-1]++;ans[i+1][j]++;ans[i+1][j+1]++;}}}memset(antu,0,sizeof(antu));int fl=0;for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){if(flag[i][j]=='x'){if(tu[i][j]=='*')    fl=1;antu[i][j]=ans[i][j]+48;}elseantu[i][j]='.';}}if(fl){for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){if(tu[i][j]=='*'){antu[i][j]='*';}}}}for(int i=1; i<=n; i++){for(int j=1; j<=n; j++){printf("%c",antu[i][j]);}printf("\n");}}return 0;
}

POJ 2612 Mine Sweeper 扫雷游戏相关推荐

  1. [C语言]扫雷游戏(Mine Sweeper)

    目录 扫雷游戏:: game.h game.c 1.打印菜单 2.初始化雷区 3.打印雷区 4.布置雷 5.排查雷 6.统计排查坐标周围雷的个数 test.c 扫雷游戏:: game.h #pragm ...

  2. java制作扫雷游戏中埋雷的难点_Java 实现经典扫雷游戏

    最后一次更新于 2019/07/08 效果演示图 Java 实现经典扫雷游戏 本扫雷游戏有以下功能: 如果点中炸弹会显示炸弹. 玩家左键点击方块能显示该方块周围会出现几个炸弹,如果不存在炸弹的话扫描范 ...

  3. 构造 - Mine Sweeper II - ICPC 2020 上海

    构造 - Mine Sweeper II - ICPC 2020 上海 题意: 给 定 两 个 n × m 的 由 ′ X ′ 和 ′ . ′ 矩 阵 A 和 B , 表 示 两 个 扫 雷 的 矩 ...

  4. python扫雷游戏_python实现扫雷小游戏

    前面我们用python实现了贪吃蛇.坦克大战.飞船大战.五子棋等游戏 今天我们用python来实现一下扫雷游戏 本游戏代码量和源文件较多 可以从我的GitHub地址中获取 构建地雷区 import r ...

  5. 使用 python 的单人AI 扫雷游戏

    运行扫雷 1.确保安装了Python 3.6+. 2.安装Pygame. 3.克隆这个存储库: 设置 minesweeper.py ⚓ 扫雷游戏表示 class Minesweeper():def _ ...

  6. c语言扫雷游戏代码_C语言游戏详解---扫雷游戏

    扫雷游戏大家应该都不陌生,一个扫雷游戏要满足的基本要求是: 1. 第一次扫的位置不能是雷 2. 每展开一个位置要显示该位置周围雷的个数 3. 若该位置周围没雷,要把周围展开 该游戏的界面是10X10的 ...

  7. java扫雷教程_java实现简单扫雷游戏

    本文实例为大家分享了java实现简单扫雷游戏的具体代码,供大家参考,具体内容如下 package com.test.swing; import java.awt.event.ActionEvent; ...

  8. [安全攻防进阶篇] 一.什么是逆向分析、逆向分析应用及经典扫雷游戏逆向

    从2019年7月开始,我来到了一个陌生的专业--网络空间安全.初入安全领域,是非常痛苦和难受的,要学的东西太多.涉及面太广,但好在自己通过分享100篇"网络安全自学"系列文章,艰难 ...

  9. C语言程序设计 | 扫雷游戏

    <扫雷>是一款大众类的益智小游戏,于1992年发行.游戏目标是在最短的时间内根据点击格子出现的数字找出所有非雷格子,同时避免踩雷,踩到一个雷即全盘皆输. 以上就是扫雷的介绍,来源百度百科. ...

最新文章

  1. ENGINEER 003:配置IPv6地址
  2. matlab中cell用法
  3. Jquery DataTable服务端分页的最佳实现
  4. 关于KVM的几篇细节文档
  5. java dom创建xml文件_Java 如何使用dom方式读取和创建xml文件
  6. angular 手动注入_手动引导Angular JS应用程序
  7. b站视频解析php,b站视频解析【调解流程】
  8. FineReport帆软报表使用入门
  9. Tilera多线程网络编程总结
  10. Selenium+Java - 结合sikuliX操作Flash网页
  11. 谷歌浏览器任务栏图标变白色解决方法(亲测有效!)
  12. java 英文句子切分_java 将英文文章 按句子,标点符号分割,正则表达式
  13. 51单片机数码管显示数字及小数点
  14. vue基础-过滤器(Filters)
  15. Docker部署服务(二)上传镜像至Habor
  16. 解决Creo 5.0在打开stl模型后,无法查看左视图,右视图
  17. directshow使用Sample Grabber采样
  18. 合格的MySQL管理员必备备份恢复与日志管理,对MySQL进行简单的操作
  19. autocad2014点击保存闪退_AutoCAD2014闪退的原因和解决方法 一打开就闪退怎么办
  20. 浅析手机网页制作流程

热门文章

  1. 微信公众平台对接C#-服务号开发配置
  2. EAS库存台账报表SQL
  3. 用户态和内核态之间的切换
  4. java 写入parquet_java-Spark:写入 parquet file数据类型时不理解的行为
  5. “递归算法”实质及过程分析
  6. Java语言中运算符号优先级
  7. JSP指令--Page指令
  8. 揭秘ROIT,拳头公司,英雄联盟游戏建模师的职位要求
  9. HTML 图片圆角不执行,css3圆角无效怎么办
  10. Android 使用MediaPlayer播放本地视频