poj 2612 Mine Sweeper
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6429 | Accepted: 2500 |
Description
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
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
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...
注意:假设踩到地雷。要把全部地雷表示出来。
#include <iostream>
using namespace std;
#define MAX 12
int n;
char map[MAX][MAX],ans[MAX][MAX];
int count(int i,int j,int n){
int ans=0;
if (map[i-1][j-1]=='*' && i-1>=0 && j-1>=0)
ans++;
if (map[i-1][j]=='*' && i-1>=0)
ans++;
if (map[i-1][j+1]=='*' && i-1>=0 && j+1<n)
ans++; if (map[i][j-1]=='*' && j-1>=0)
ans++;
if (map[i][j]=='*')
ans++;
if (map[i][j+1]=='*' && j+1<n)
ans++; if (map[i+1][j-1]=='*' && i+1<n && j-1>=0)
ans++;
if (map[i+1][j]=='*' && i+1<n)
ans++;
if (map[i+1][j+1]=='*' && i+1<n && j+1<n)
ans++;
return ans;
}
int main(){ while (cin>>n){
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
cin>>map[i][j];
int flag=0;
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
cin>>ans[i][j];
if (map[i][j]=='*' && ans[i][j]=='x')
flag=1;
if (ans[i][j]=='x'){
int k=count(i,j,n);
ans[i][j]=k+'0';
}
}
}
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if (flag==1 && map[i][j]=='*')
cout<<map[i][j];
else
cout<<ans[i][j];
}
cout<<endl;
}
}
return 0;
}
poj 2612 Mine Sweeper的更多相关文章
- 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)
HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...
- POJ 2612
#include<iostream> #include<stdio.h> #include<algorithm> #define MAXN 11 using nam ...
- 2020杭电多校 C / HDU 6879 - Mine Sweeper
题意: t组输入,每组输入一个s 你需要输出一个r行c列的阵列,这个阵列中'X'代表炸弹,'.'表示没有炸弹 对于'.'这些位置都会有一个数值,这个值取决于这个位置附近8个位置,这8个位置一共有几个炸 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- 多级弹出菜单jQuery插件ZoneMenu
ZoneMenu是一个菜单jQuery插件,只需占用页面上的一个小区域,却可以实现多级菜单. 在线体验:http://keleyi.com/jq/zonemenu/ 点击这里下载 完整HTML文件代码 ...
- 中英文代码对比系列之Java一例
原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...
- 2017-11-09 中英文代码对比系列之Java一例
原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时 ...
- FZU1920 Left Mouse Button(dfs)
Problem 1920 Left Mouse Button Accept: 385 Submit: 719 Time Limit: 1000 mSec Memory Limit : 3 ...
- [转]分享20佳好玩的 jQuery 游戏
本文转自:http://www.cnblogs.com/lhb25/archive/2011/04/17/2001089.html jQuery是时下最流行的 JavaScript 库.现在,除了HT ...
随机推荐
- UML基本架构建模--获取类
Getting Started 開始 Modeling a system involves identifying the things that are important to your p ...
- 深刻理解Nginx之基本配置和升级(2)
3 Nginx基本配置 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvam9obl9mX2xhdQ==/font/5a6L5L2T/fontsize/400 ...
- HTML5 Canvas 获取网页的像素值。
我之前在网上看过一个插件叫做出JScolor 颜色拾取器 说白了就是通过1*1PX的DOM设置颜色值通过JS来获取当前鼠标点击位置DOM的颜色值. 自从HTML5 画布出来之后.就有更好的方法来 ...
- c#自己实现线程池功能(二)
介绍 在上一篇c#自己实现线程池功能(一)中,我们基本实现了一个能够执行的程序.而不能真正的称作线程池.因为是上篇中的代码有个致命的bug那就是没有任务是并非等待,而是疯狂的进行while循环,并试图 ...
- BZOJ1492:[NOI2007]货币兑换 (CDQ分治+斜率优化DP | splay动态维护凸包)
BZOJ1492:[NOI2007]货币兑换 题目传送门 [问题描述] 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和B纪念券(以下简称B券).每个持有金券的 ...
- 英语发音规则---X字母
英语发音规则---X字母 一.总结 一句话总结: 1.x位于词尾或音节尾部,读/ks/? box /bɒks/ n.盒; 箱状物 fix /fɪks/ vt.固定 fox /fɒks/ n.狐; 狐狸 ...
- 2019黑马JAVAEE57期基础班就业班(全套)
黑马java57期 百度网盘 2019黑马JAVAEE57期基础班就业班(全套)百度网盘 下载 Spring全家桶解决方案 - 微服务认证解决方案(JWT) - 微服务网关解决方案(Zuul) 黑马j ...
- 19. Remove Nth Node From End of List[M]删除链表的倒数第N个节点
题目 Given a linked list, remove the n-th node from the end of list and return its head. *Example: Giv ...
- 备份IIS
备份IIS,这里实质指的是备份IIS配置.如果要备份IIS部署的网站的话,直接Copy目录就行了. 备份IIS配置其实和备份系统含义差不多,为了方便系统或者IIS出现故障后能够及时恢复到某节点上,所以 ...
- getElementsByClassName 方法兼容性封装方法二
var getElmsByClsName = function(className, results) { results = results || []; // 判断浏览器是否支持 getEleme ...