zoj 2110 Tempter of the Bone (dfs)
Tempter of the Bone
Time Limit: 2 Seconds Memory Limit: 65536 KB
The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone was a trap, and he tried desperately to get out of this maze.
The maze was a rectangle with sizes N by M. There was a door in the maze. At the beginning, the door was closed and it would open at the T-th second for a short period of time (less than 1 second). Therefore the doggie had to arrive at the door on exactly the T-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once he entered a block, the ground of this block would start to sink and disappear in the next second. He could not stay at one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.
Input
The input consists of multiple test cases. The first line of each test case contains three integers N, M, and T (1 < N, M < 7; 0 < T < 50), which denote the sizes of the maze and the time at which the door will open, respectively. The next N lines give the maze layout, with each line containing M characters. A character is one of the following:
'X': a block of wall, which the doggie cannot enter;
'S': the start point of the doggie;
'D': the Door; or
'.': an empty block.
The input is terminated with three 0's. This test case is not to be processed.
Output
For each test case, print in one line "YES" if the doggie can survive, or "NO" otherwise.
Sample Input
4 4 5
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
Sample Output
NO
YES
Author: ZHANG, Zheng
Source: Zhejiang Provincial Programming Contest 2004
//C++ 20 172 姜伯约
/* 题意:
从S走向D,问能否恰好在第t个时刻走到 DFS:
比较经典的一道深搜,奇偶剪枝是比较亮的一点,亲可以自己手动画图
比较一下,会获益不少,其他和普通的dfs差不多。 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int n,m,t;
char g[][];
int mov[][]={,,,,,-,-,};
int flag,ex,ey;
void dfs(int x,int y,int cnt)
{
if(cnt>t || flag) return;
if(x==ex && y==ey && cnt==t) flag=;
int temp=(t-cnt)-abs(x-ex)-abs(y-ey);
if(temp< || (temp&))return; //奇偶剪枝
for(int i=;i<;i++){
int tx=x+mov[i][];
int ty=y+mov[i][];
if(tx>= && tx<n && ty>= && ty<m && g[tx][ty]!='X'){
g[tx][ty]='X';
dfs(tx,ty,cnt+);
g[tx][ty]='.';
}
}
}
int main(void)
{
while(scanf("%d%d%d",&n,&m,&t)!=EOF&&(n+m+t))
{
int x,y;
int cnt=;
for(int i=;i<n;i++){
scanf("%s",g[i]);
for(int j=;j<m;j++){
if(g[i][j]=='S')
x=i,y=j;
else if(g[i][j]=='.') cnt++;
else if(g[i][j]=='D') ex=i,ey=j;
}
}
if(cnt+<t){
puts("NO");continue;
}
flag=;
g[x][y]='X';
dfs(x,y,);
if(flag) puts("YES");
else puts("NO");
}
return ;
}
zoj 2110 Tempter of the Bone (dfs)的更多相关文章
- ZOJ 2110 Tempter of the Bone(条件迷宫DFS,HDU1010)
题意 一仅仅狗要逃离迷宫 能够往上下左右4个方向走 每走一步耗时1s 每一个格子仅仅能走一次且迷宫的门仅仅在t时刻打开一次 问狗是否有可能逃离这个迷宫 直接DFS 直道找到满足条件的路径 ...
- ZOJ 2110 Tempter of the Bone
Tempter of the Bone Time Limit: 2 Seconds Memory Limit: 65536 KB The doggie found a bone in an ...
- ZOJ 2110 Tempter of the Bone(DFS)
点我看题目 题意 : 一个N×M的迷宫,D是门的位置,门会在第T秒开启,而开启时间小于1秒,问能否在T秒的时候到达门的位置,如果能输出YES,否则NO. 思路 :DFS一下就可以,不过要注意下一终止条 ...
- HDU1010:Tempter of the Bone(dfs+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
随机推荐
- Oracle SCN与时间的相互转换
1.SCN转换成时间 select scn_to_timestamp(current_scn) from v$database; 2.时间转换成SCN select timestamp_to_scn( ...
- Python 初始—(多级字典)
字典中 嵌套字典 如同json 对象, data={ "msg":{ “xxx.com”:["a","b"] } } data.values ...
- pip命令小结
pip的另一种调用方式 python -m pip通过指定python的名字来指定特定的pip pip freeze > 项目目录/requirements.txt导出pip中下载的包目录 pi ...
- BAT及各大互联网公司2014前端笔试面试题
很多面试题是我自己面试BAT亲身经历碰到的.整理分享出来希望更多的前端er共同进步吧,不仅适用于求职者,对于巩固复习前端基础更是大有裨益. 而更多的题目是我一路以来收集的,也有往年的,答案不确保一定正 ...
- Nginx+php+mysql+wordpress搭建自己的博客站点
服务器环境要求Centos 6 或以上版本(由于我们的目标是半小时内搭建好,那就选简单yum安装)MySQL 5或更新版本Nginx 1或更新版本PHP 5 或更新版本 php-fpm 5或更新版本 ...
- Navicat-12.0.26的激活
1.卸载掉早期版本,卸载干净,然后安装最新版Navicat(使用群文件中Iobit uninstaller8卸载) 2.安装完成后将破解补丁复制到安装目录下,运行破解补丁. 4.先patch,然后选择 ...
- MAC中向阿里云服务器上传文件
打开mac中的终端 使用命令:$scp /local/file user@remote:/file /local/file 是本地文件 后面部分[用户名]@[ip地址:][服务器中的文件目录] not ...
- Docker虚拟化容器的使用
Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Li ...
- axios进行ajax请求得不到数据,cookie无法携带问题
这个坑也是很早之前踩过,今天做项目的时候居然忘了,怎么都拿不到数据,果然好记性不如烂笔头,决定写篇博客来祭奠下我的猪脑子: 原因可能就是你发送请求的时候,需要设置cookie,然而你的cookie并没 ...
- php-5.6.26源代码 - PHP文件汇编成opcode(require、include的差异)
文件 php-5.6.26/Zend/zend_language_scanner.c ZEND_API zend_op_array *compile_file(zend_file_handle *fi ...