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, 后来想了半天才知道哪里有遗漏.最大的问题 ...
随机推荐
- DB2 添加license
DB2 - DB2COPY1 - DB2-0 服务不能启动报的错是这样的:Microsoft Management Console Windows 不能在 本地计算机 启动 DB2 - DB2.有 ...
- Xcode更新至IOS 9 后错误处理
1.obtain an updated library from the vendor, or disable bitcode for this target. for architecture ar ...
- Java Serializable(序列化)的理解和总结
1.序列化是干什么的? 简单说就是为了保存在内存中的各种对象的状态(也就是实例变量,不是方法),并且可以把保存的对象状态再读出来.虽然你可以用你自己的各种各样的方法来保存object st ...
- javascript 视频播放指定的时间段
javascript 视频播放指定的时间段 一.html5 vedio: //指定开始时间 player.currentTime=startPoint; player.play(); //使用事件来控 ...
- curl下载目录
http://ftp.loongnix.org/os/loongnix/1.0/SRPMS/ wget wget -c -r -np -k -L -p
- django使用auth模块进行身份认证
https://docs.djangoproject.com/zh-hans/2.0/topics/auth/default/#authentication-in-web-requests djang ...
- 【转】C# WinForm获取当前路径汇总
源地址:https://www.cnblogs.com/greatverve/archive/2011/12/15/winform-path.html
- VS2013安装及破解教程
https://blog.csdn.net/qq_33742119/article/details/80075352 软件下载的百度云链接,也可以在官网直接下载 链接:https://pan.baid ...
- numpy.histogram 官方手册
numpy.histogram numpy.histogram(a, bins=10, range=None, normed=False, weights=None, density=None) Co ...
- 你必须知道的----C语言笔试面试中经典易错的一些知识点(持续更新)
1. 关于二级指针的解析和引用 1.1 二级指针意义 二级指针存放的是一级指针的地址 Ex: Int a = ; Int *p = &a; Int **q = &p; 1.2 ...