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, 后来想了半天才知道哪里有遗漏.最大的问题 ...
随机推荐
- java类创建时里面成员执行的先后顺序
静态代码块在类第一次使用的时候执行一次,在构造函数执行之前执行.只要用到类,哪怕new对象(比如只声明变量)也会被执行,且只执行一次.一般用于对类进行初始化. 先执行静态代码块,静态成员(谁在前就先执 ...
- CreateExcel 导出Excel
public class CreateExcel { /// <summary> /// 用Excel组件导出Excel文件 /// </summary> /// <pa ...
- 我用Django搭网站(3)-表单RSA加密
之前开发项目时因为种种原因一直使用明文提交,表单直接明文提交非常不安全,只要稍加操作就能轻易获取用户的信息.在众里寻他千百度之后决定使用RSA加密方式,简单可靠. 项目准备 一.安装PyCrypto库 ...
- Android中如何下载文件并显示下载进度
原文地址:http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1125/2057.html 这里主要讨论三种方式:AsyncTask.Serv ...
- thedao
TheDao 简化版解释 the Dao 合约 contract f1{ function transfer() { if (acccount[m]>=100) { m.send(100) ac ...
- java 图书馆系统 练习
话不多说 娱乐 ================================================== book 类(书本的基础属性) package 图书管理系统01; /** * @ ...
- 看了这篇Dubbo RPC面试题,让天下没有难面的面试题!
前言: RPC非常重要,很多人面试的时候都挂在了这个地方!你要是还不懂RPC是什么?他的基本原理是什么?你一定要把下边的内容记起来!好好研究一下!特别是文中给出的一张关于RPC的基本流程图,重点中 ...
- 如何下载网页上的视频 并且 flv 格式转化成 MP4
链接:http://www.jb51.net/softjc/222135.html https://jingyan.baidu.com/article/25648fc162f2899190fd0042 ...
- docker镜像的创建
获得更多资料欢迎进入我的网站或者 csdn或者博客园 昨天讲解了docker的安装与基本使用,今天给大家讲解下docker镜像的创建的方法,以及push到Docker Hub docker安装请点击右 ...
- Python获取网页Html文本
Python爬虫基础 1.获取网页文本 通过urllib2包,根据url获取网页的html文本内容并返回 #coding:utf-8 import requests, json, time, re, ...