TOJ 3184 Mine sweeping
描述
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....
.....
.....
.....
.....
题目来源
扫雷游戏~
#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的更多相关文章
- 8659 Mine Sweeping
时间限制:500MS 内存限制:65535K提交次数:37 通过次数:15 题型: 编程题 语言: G++;GCC Description The opening ceremony of the ...
- 【HDOJ】3316 Mine sweeping
简单BFS. #include <iostream> #include <cstdio> #include <cstring> #include <cstdl ...
- Mine Number(搜索,暴力) ACM省赛第三届 G
Mine Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Every one once played the gam ...
- [2012山东省第三届ACM大学生程序设计竞赛]——Mine Number
Mine Number 题目:http://acm.sdut.edu.cn/sdutoj/problem.php? action=showproblem&problemid=2410 Time ...
- C language 模拟 win的经典游戏——扫雷
让我们在terminal下愉快的...扫雷 昨天跟奇葩霖聊起"雷区"这个敏感词汇,然后非常荣幸的... 应该轰炸不到我.. . 后来百无聊赖的去玩了把扫雷.然后发现我之前都是乱扫的 ...
- SVN版本冲突,导致出现Files 的值“ < < < < < < < .mine”无效
只要根据错误提示,找到相应文件夹下的\obj\Debug文件夹下的 相应名字.csproj.FileListAbsolute.txt, 打开并删除含有'<<<<<< ...
- Files 的值“<<<<<<< .mine”无效。路径中具有非法字符
解决冲突,告诉SVN这个问题已解决(Resolved). 一般更简单些:在你的工程OBJ/DEBUG目录下,找到 工程名.csproj.FileListAbsolute.txt的文件打开并删除含有'& ...
- SVN Files 的值“ < < < < < < < .mine”无效。路径中具有非法字符。
错误 1 Files 的值“ < < < < < < < .mine”无效.路径中具有非法字符. 今天使用SVN进行更新的时候,出现了如上问题,想起卓 ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
随机推荐
- SharePoint Server 2013 Excel Web Access无法显示
环境信息:SharePoint Server 2013 中文版,版本为15.0.4420.1017 Windows Server 2008 r2中文版 Sql Server 2012 问题描述:在Sh ...
- Ubuntu下vi编辑器不听话
编辑文件/etc/vim/vimrc.tiny,将“compatible”改成“nocompatible”非兼容模式: 并添加一句:set backspace=2
- C# 控制win7任务栏、开始菜单的显示与隐藏
因为是做显示程序,故需要控制任务栏与开始菜单的显示与隐藏,这样就美观些.不啰嗦.直接上代码: using System; using System.Collections.Generic; using ...
- Castle Windsor 注册组件
1.逐个注册组件即对每个接口通过代码指定其实现类,代码: container.Register( Component.For<IMyService>() //接口 .Implemented ...
- WPF的Image控件图片不能显示出来的问题探究
在wpf项目中,用Image来显示资源图片,在界面是可以显示,但是在运行的时候却显示不出来. <Image Source=" HorizontalAlignment="Lef ...
- ecliplse集成反编译插件
言语不清晰,上图最直接 搜索框输入:Decompiler 等待安装: 重启之后进入下面的界面: 8.对反编译器( Decompiler )进行配置 二.配置说明 1.缺省类反编译器(Default C ...
- day01.1-Python编译器的安装
一. 在Windows环境中安装Python编译器 1. 访问Python官网https://www.python.org,下载适用于Windows环境的相关编译器版本: 2. 点击Pytho ...
- 不值一提,却又不得不提的“CSS文本超出部分省略号代替”
偶然看到一篇类似css技巧与经验总结的文章,其中有一部分非常熟悉,那就是“css控制元素内文本超出部分使用省略号代替”,一般实际工作中, 很多产品经理会对页面UI有这样的要求.还记得,第一次做这个功能 ...
- I/O(输入/输出)---字节流与字符流
流: 分为输入流和输出流,输入/输出是相对计算机内存来说的,数据输入到内存是输入流,数据从内存中输出是输出流. 流对象构造的时候会和数据源联系起来. 数据源分为:源数据源和目标数据源.输入流联系的是源 ...
- FireFox调试代码技巧
本文版权归 csdn DyncRole 所有,此处为技术收藏,如有再转请标明原创作者及出处,以示尊重! 作者:DyncRole 原文:http://blog.csdn.net/qqhjqs/artic ...