描述

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. C# File类常用方法

    File 类 提供用于创建.复制.删除.移动和打开文件的静态方法,并协助创建 FileStream 对象. 1. File.Exists ——  确定指定的文件是否存在. public static ...

  2. C# 读取Text文本,写入Text文本

    //读取 private void showMess() { this.dataGridViewX2.Rows.Clear(); //将车辆信息一行行添加到datagreatview 里面 Strea ...

  3. cinder create volume的流程(1)

    前提:代码的跟踪,使用的是ocata版本 零.执行cinder create 命令,创建数据卷,打开debug开关 [root@osnode241001 ~]# cinder --debug crea ...

  4. python之路径拼接urljoin

    方法一:使用+进行路径拼接 url='http://ip/ path='api/user/login' url+path拼接后的路径为'http://ip//api/user/login' 方法二:使 ...

  5. python 安装虚拟环境步骤

    1.python3.6.3 注: 1.安装的时候,装上你的pip 2.安装的时候,把环境变量记得勾选 3.如果你手动更改安装位置,更改到随意的盘根目录下 2.MySQL      pycharm最好安 ...

  6. 【Thread】线程工厂-ThreadFactory

    ThreadFactory---线程工厂 在apollo源码中有这么一段代码 ExecutorService m_longPollingService = Executors.newSingleThr ...

  7. 【洛谷2416】泡芙(Tarjan+LCA)

    题目描述 火星猫经过一番努力终于到达了冥王星.他发现冥王星有 \(N\) 座城市,\(M\) 条无向边.火星猫准备出发去找冥王兔,他听说有若干泡芙掉落在一些边上,他准备采集一些去送给冥王兔.但是火星猫 ...

  8. [llvm] LLVM 核心类简明示例 : llvm::Value && llvm::Type && llvm::Constant

    LLVM 核心类简明示例 : llvm::Value && llvm::Type && llvm::Constant llvm核心类位于 include/llvm/IR ...

  9. SDUT OJ 数据结构实验之二叉树五:层序遍历

    数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  10. 《Andrew Ng深度学习》笔记1

    深度学习概论 1.什么是神经网络? 2.用神经网络来监督学习 3.为什么神经网络会火起来? 1.什么是神经网络? 深度学习指的是训练神经网络.通俗的话,就是通过对数据的分析与计算发现自变量与因变量的映 ...