poj 2612 Mine Sweeper

Mine Sweeper

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6429   Accepted: 2500

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...

注意:如果踩到地雷,要把所有地雷表示出来;

#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;
}
时间: 2024-10-26 20:18:06

poj 2612 Mine Sweeper的相关文章

HOJ 题目分类

转自:http://blog.sina.com.cn/s/blog_65f3869301011a1o.html ******************************************************************************* 简单题(包括枚举,二分查找,(复杂)模拟,基础数据结构(栈.队列),杂题等 ****************************************************************************

BFS学习总结

BFS学习总结 给你一个n*m的网格迷宫,迷宫中有些格子不能走,其他的格子都能走.然后给你起点与终点,问你从起点走到终点最少需要多少步? 上面的问题就是一个典型的BFS问题,对于这类问题来说,只要你掌握了这类问题的关键思想,其实他们都是可以用类似的思路来做的. 你可以把BFS问题想象成:从一个父亲(起点状态)生儿子(后继状态),儿子又生孙子(后继状态)的过程,只要这个家族中出生了一个满意的后代(终点状态),这个家族就不生了. 但是如果这个家族中有两个完全一样的人出生(他们的辈分不一定相同),那么

FZU 1920

Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mark them out. You mark them by clicking your right mouse button. Then you will place a little flag where you think the mi

第一次组队赛---2010年全国大学生程序设计邀请赛(福州)L

L - Left Mouse Button Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 1920 Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mi

[转]分享20佳好玩的 jQuery 游戏

本文转自:http://www.cnblogs.com/lhb25/archive/2011/04/17/2001089.html jQuery是时下最流行的 JavaScript 库.现在,除了HTML5以外,也有很多jQuery爱好者使用jQuery来开发游戏,虽然效果没有Flash那么好,但是这些游戏也看起来很酷.今天本文收集了20佳基于jQuery开发的特色游戏,一起来欣赏吧! 1- Tetris with jQuery 2- Game Query- Game engine for jQ

FZU - 1920 Left Mouse Button

FZU - 1920 Left Mouse Button Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description Mine sweeper is a very popular small game in Windows operating system. The object of the game is to find mines, and mar

多级弹出菜单jQuery插件ZoneMenu

ZoneMenu是一个菜单jQuery插件,只需占用页面上的一个小区域,却可以实现多级菜单. 在线体验:http://keleyi.com/jq/zonemenu/ 点击这里下载 完整HTML文件代码: <!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <titl

优质题表(机密版)

转载请注明出处:http://www.cnblogs.com/dashuzhilin/p/4556803.html 思维题: poj 1528 poj 1597 poj 2538 poj 2608 poj 2612 poj 2361 poj 2339 poj 2664 uva 10894 uva 10921   uva 10922   uva 10929 uva 10931   uva 10800   uva 10878 uva 10976   uva 10323   uva 201 poj 2

中英文代码对比系列之Java一例

原文: https://zhuanlan.zhihu.com/p/30905033. 作者为本人. 这个系列将对同一段代码进行中文命名和英文命名两个版本的比较. 目的包括, 演示中文命名, 发现命名时可能遇到的问题, 探讨代码风格(中文命名的'套路')等. 示例中的命名风格仅基于个人非常有限的实践, 希望抛砖引玉. 不在讨论范围内的是: 中英文代码的可读性孰高孰低. 个人相信用英文和中文都能写出可读性很好的代码. 区别仅在于母语不同的开发者对哪个版本更敏感, 读写维护起来更省工. 原代码本身的优