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 2732 Leapin' Lizards(拆点+最大流)
HDU 2732 Leapin' Lizards 题目链接 题意:有一些蜥蜴在一个迷宫里面,有一个跳跃力表示能跳到多远的柱子,然后每根柱子最多被跳一定次数,求这些蜥蜴还有多少是不管怎样都逃不出来的. ...
- .NET 图片解密为BASE64
#region 图片加密 /// <summary> /// 加密本地文件 /// </summary> /// <param name="inputname& ...
- [Java开发之路](7)RandomAccessFile类具体解释
RandomAccessFile适用于大小已知的记录组成的文件.提供的对文件訪问.既能够读文件.也能够写文件,而且支持随机訪问文件.能够訪问文件的任何位置. 文件里记录的大小不一定都同样.仅仅要我们知 ...
- 【ASP】在特定的范围内产生N个不同的随机数
ASP产生一个随机数不难.就两条特定语句: <% Randomize x=int(20*rnd+1) %> 以上的两条语句.表示从1~20这个范围内产生随机数,而且这些随机数都是整数. 那 ...
- nyoj-647-奋斗小蜗牛在请客(进制转换)
奋斗小蜗牛在请客 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 一路艰辛一路收获.成功爬过金字塔的小蜗牛别提多高兴了.这不为了向以前帮助他的哥们们表达谢意,蜗牛宴请 ...
- oracle存储过程的使用
一. 使用for循环游标:遍历全部职位为经理的雇员 1. 定义游标(游标就是一个小集合) 2. 定义游标变量 3. 使用for循环游标 declare -- 定义游标c_job cursor c_jo ...
- java基础——transient
今天在看struts1源代码的时候,发如今ActionForm中首先声明了两个transient类型的protected变量. 之前没有接触过该transient类型,所以就查了查. transien ...
- 0x25 广度优先搜索
今天莫名不想说话. 结果发现效率挺高? poj3322 本来可以1a的..发现我宽搜写的是head<=tail而且初始是head=1,tail=2如果是多组数据简直就gg了.基础不牢固 这题虽然 ...
- hdoj--2522--A simple problem(数学模拟)
A simple problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- bfs初学
BFS: ** 当知道初始和目标状态的,用双向BFS: 无权图最好用BFS 不用重复如队** 实现框架: 抄来的(来源:https://www.luogu.org/blog/stephen2333/s ...