描述

I think most of you are using system named of xp or vista or win7.And these system is consist of a famous game what is mine sweeping.You must have played it before.If you not,just look the game rules followed.

There
are N*N grids on the map which contains some mines , and if you touch
that ,you lose the game.If a position not containing a mine is touched,
an integer K (0 < =K <= 8) appears indicating that there are K
mines in the eight adjacent positions. If K = 0, the eight adjacent
positions will be touched automatically, new numbers will appear and
this process is repeated until no new number is 0. Your task is to mark
the mines' positions without touching them.

Now, given the distribution of the mines, output the numbers appearing after the player's first touch.

输入

The
first line of each case is two numbers N (1 <= N <= 100) .Then
there will be a map contain N*N grids.The map is just contain O and
X.'X' stands for a mine, 'O' stand for it is safe with nothing. You can
assume there is at most one mine in one position. The last line of each
case is two numbers X and Y(0<=X<N,0<=Y<N, indicating the
position of the player's first touch.

输出

If the player touches the mine, just output "it is a beiju!".

If
the player doesn't touch the mine, output the numbers appearing after
the touch. If a position is touched by the player or by the computer
automatically, output the number. If a position is not touched, output a
dot '.'.

Output a blank line after each test case.

样例输入

5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
1 1
5
OOOOO
OXXXO
OOOOO
OXXXO
OOOOO
0 0

样例输出

it is a beiju!

1....
.....
.....
.....
.....

题目来源

HDOJ

扫雷游戏~

#include <stdio.h>
#include <string.h>
#define MAXN 150
int N;
int flag[MAXN][MAXN];
char map[MAXN][MAXN];
char out[MAXN][MAXN];
int judge(int x, int y){
int flag=0;
for(int i=x-1; i<=x+1; i++){
for(int j=y-1; j<=y+1; j++){
if(1<=i && i<=N && 1<=j && j<=N && !(i==x&&j==y)){
if(map[i][j]=='X')flag++;
}
}
}
return flag;
}
void dfs(int x, int y){
int sum=judge(x,y);
if(sum==0){
out[x][y]='0';
for(int i=x-1; i<=x+1; i++){
for(int j=y-1; j<=y+1; j++){
if(1<=i && i<=N && 1<=j && j<=N && !(i==x&&j==y)){
if(!flag[i][j])
dfs(i,j);
}
flag[i][j]=1;
}
}
}else{
out[x][y]=sum+'0';
}
}
int main()
{
while( scanf("%d",&N)!=EOF ){
for(int i=1; i<=N; i++){
getchar();
for(int j=1; j<=N; j++){
scanf("%c",&map[i][j]);
}
}
int x,y;
scanf("%d %d",&x,&y);
x++;
y++;
if(map[x][y]=='X'){
puts("it is a beiju!\n");
continue;
}
memset(flag,0,sizeof(flag));
memset(out,'.',sizeof(out));
dfs(x,y);
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
printf("%c",out[i][j]);
}
printf("\n");
}
printf("\n");
}
return 0;
}

TOJ 3184 Mine sweeping的更多相关文章

  1. 8659 Mine Sweeping

    时间限制:500MS  内存限制:65535K提交次数:37 通过次数:15 题型: 编程题   语言: G++;GCC Description The opening ceremony of the ...

  2. 【HDOJ】3316 Mine sweeping

    简单BFS. #include <iostream> #include <cstdio> #include <cstring> #include <cstdl ...

  3. Mine Number(搜索,暴力) ACM省赛第三届 G

    Mine Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Every one once played the gam ...

  4. [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number

    Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...

  5. C language 模拟 win的经典游戏——扫雷

    让我们在terminal下愉快的...扫雷 昨天跟奇葩霖聊起"雷区"这个敏感词汇,然后非常荣幸的... 应该轰炸不到我.. . 后来百无聊赖的去玩了把扫雷.然后发现我之前都是乱扫的 ...

  6. SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效

    只要根据错误提示,找到相应文件夹下的\obj\Debug文件夹下的 相应名字.csproj.FileListAbsolute.txt, 打开并删除含有'<<<<<< ...

  7. Files 的值“<<<<<<< .mine”无效。路径中具有非法字符

    解决冲突,告诉SVN这个问题已解决(Resolved). 一般更简单些:在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有'& ...

  8. SVN Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。

    错误 1 Files 的值“ < < < < < < < .mine”无效.路径中具有非法字符.     今天使用SVN进行更新的时候,出现了如上问题,想起卓 ...

  9. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

随机推荐

  1. 【转】Android android listview的HeadView左右切换图片(仿新浪,网易,百度等切换图片)

    首先我们还是看一些示例:(网易,新浪,百度)      下面我简单的介绍下实现方法:其实就是listview addHeaderView.只不过这个view是一个可以切换图片的view,至于这个vie ...

  2. C# worksheet设置Excel样式

    1.例子导出Excel的样式 样式代码 public void Exportdatagridviewtoexcel(string Textname) { SaveFileDialog savedial ...

  3. Dynamically loading unmanaged OCX in C#

    You'll have to perform a number of steps that are normally taken of automatically when you use the t ...

  4. Kotlin 字符模板

    Kotlin的字符模板和c语言的格式化输出有点像. 先来说说Kotlin 的字符模板怎么弄. fun main(args:Array<String>) { var name="T ...

  5. VINS-Mono Installation

    Prerequisites 1.1 ** Ubuntu 16.04, ROS Kinetic ** sudo apt-get install ros-kinetic-cv-bridge ros-kin ...

  6. 【大数据系统架构师】0.3 MySQL数据库

    1. MySQL的基本操作 2. SQL语句 3. 高级查询 1)聚合函数.分组查询 2)联合查询.连接查询 3)子查询 4. 高级应用 1)视图与索引 2)数据可视化管理 5. 使用JDBC操作数据 ...

  7. tcp连接过程中的三次握手和四次挥手

    在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手握手建立连接 @第一次握手: 建立连接是,客户端A发送SYN包到服务器B,并进入SYN_SEND状态,等待B确认. @第二次握手: 服务 ...

  8. HDU6336-2018ACM暑假多校联合训练4-1005-Problem E. Matrix from Arrays-前缀和

    题意是给了一种矩阵的生成方式 让你求两个左边之间的矩阵里面的数加起来的和(不是求矩阵的值) 没看标程之前硬撸写了160行 用了前缀和以后代码量缩短到原来的1/3 根据规律可以推导出这个矩阵是在不断重复 ...

  9. 错误代码: 1142 REFERENCES command denied to user 'wuyong'@'localhost' for table 'orders'

    错误代码: 1142 REFERENCES command denied to user 'wuyong'@'localhost' for table 'orders' 原因:在使用SQLyog操作数 ...

  10. ionic中文教程[来自皓眸大前端]

    做前端的同学有福了,学完比较热火的angular,你就可以开始动手做静态的WebApp了,这是多么幸福的一件事啊.静态的WebApp,你可以做任何的Demo,甚至可以做一些通关小游戏这个先不谈.做完了 ...