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 ...
随机推荐
- HDU 5372 Segment Game
/** 多校联合2015-muti7-1004 <a target=_blank href="http://acm.hdu.edu.cn/showproblem.php?pid=537 ...
- NYOJ_94 cigarettes 递归VS迭代
题目地址 分析: 英文题事实上看懂意思和正常的也都差点儿相同.就算有几个单词不认识也无伤大雅. 一共同拥有n支烟,每天抽k支. 每抽完k支,会得到一仅仅. a组数据. 输入n k的个数.输出一共抽了 ...
- Educational Codeforces Round 12 E. Beautiful Subarrays trie求两异或值大于等于k对数
E. Beautiful Subarrays One day, ZS the Coder wrote down an array of integers a with elements a1, ...
- springmvc生成注册验证码
通过SPRing MVC为系统添加验证码 1:布局登陆页面,用户名,密码,填写验证码的文本框,及验证码的图片及点击换图 <%@ taglib prefix="c" uri=& ...
- JQuery学习系列篇(一)
jQuery是一套Javascript脚本库:注意jQuery是脚本库, 而不是脚本框架. "库"不等于"框架", 比如"System程序集" ...
- 图片词典 Picture Dictionary
图片词典/可视词典 Picture Dictionary 某些 APP 又有新功能可以加入了.
- iOS开发者账号证书配置及相关工作
申请到开发者账号,肯定要先配置一下才可以使用,这主要是iOS证书及配置文件: 以下这篇文章写得比较全面,故不再累赘,需要的同学可以看一下: iOS开发证书与配置文件的使用
- CheckBox的Attributes
在看老同事写的代码的时候,发现了这样的一段代码:之前自己没有遇到过,记录下吧. 大致是这样的 foreach (GridViewRow grv in GridView1.Rows) { CheckBo ...
- genemotion
genemotion 问题 https://blog.csdn.net/beiminglei/article/details/17399333 https://www.jianshu.com/p/f8 ...
- 蓝桥杯_left and throw
思考了许久没有结果,最后,还是一位擅长搜索资源的学长帮我找到了一个不错的代码,这个代码极其精妙,再一次印证了一句话,没有做不到的,只有想不到的,当然这个代码我拿到手的时候是个没有注释的代码,我费尽周折 ...