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 & % ...
随机推荐
- JavaScript的算术、赋值、关系运算符的讲解
JS中的运算符分为:算术/赋值/关系/逻辑/字符串 算术运算符: +加法 -减法 *乘法 /除法 %取余 var a = 1, b = 2; a + b = 3 ...
- C/C++获取本机名+本机IP+本机MAC
本机名.IP.MAC都是一些比较常用网络参数,怎么用C/C++获取呢? 研究了两三个小时... 需要说明的都在代码注释里 #include <stdio.h> #include <W ...
- IntelliJ IDEA 方法注释教程
首先Ctrl +Alt +S ,打开Settings ,找到Live Template,然后点击右侧的绿色的“+”,选择Template Group 然后给新建的Group随便命个名 选中自己刚才创建 ...
- ajax状态值和状态码
AJAX状态值是指,运行AJAX所经历过的几种状态,无论访问是否成功都将响应的步骤,可以理解成为AJAX运行步骤.如:正在发送,正在响应等,由AJAX对象与服务器交互时所得:使用“ajax.ready ...
- JS常用数组方法及实例
1.join(separator):将数组的元素组起一个字符串,以separator为分隔符 ,,,,]; var b = a.join("|"); //如果不用分隔符,默认逗号隔 ...
- 简单php实现同一时间内一个账户只允许在一个终端登陆
在账户表的基础上,我新建了一个账户account_session表,用来记录登录账户的account_id和最新一次登录成功用户的session_id,然后首先要修改登录方法:每次登录成功后,要将登录 ...
- python基础之数据类型与变量patr2
一.元素分类 有如下值集合 [11,22,33,44,55,66,77,88,99,90...],将所有大于 66 的值保存至字典的第一个key中,将小于 66 的值保存至第二个key的值中. 即: ...
- CSS3 Flexbox(伸缩盒/弹性盒模型)可视化指南
在http://css.doyoe.com/(CSS参考手册)中,本文对应其中的伸缩盒 引入 Flexbox布局官方称为CSS Flexible Box Layout Module是一个CSS3新的布 ...
- P2985 [USACO10FEB]吃巧克力Chocolate Eating
P2985 [USACO10FEB]吃巧克力Chocolate Eating 题目描述 Bessie has received N (1 <= N <= 50,000) chocolate ...
- 您的手机上未安装应用程序 android 点击快捷方式提示未安装程序的解决
最近APP出现一个很奇怪的问题,在Android 4.4.2和android 4.4.3系统上点击应用的快捷方式,打不开应用,而且会提示未安装程序. 确认了应用的MainActivity中设置了and ...