Tempter of the Bone

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
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 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 ( < N, M < ; < T < ), 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 '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 S.X.
..X.
..XD
.... S.X.
..X.
...D Sample Output
NO
YES Author
ZHANG, Zheng Source
ZJCPC2004 Recommend
JGShining
#include <iostream>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int
sx,sy,ex,ey;
int
n,m;
int
flag;
int
d[][]={,,,,,-,-,};
char
map[][];
void
dfs(int x,int y,int t)
{

//cout<<x<<" "<<y<<" "<<t<<endl;
if(flag==)return;
if
(t<sqrt(float((ex-x)*(ex-x)+(ey-y)*(ey-y)))||(t-abs(ex-x)+abs(ey-y))%)return;
else if
(t==)
{

if
(x==ex&&y==ey){flag=;return;}
else
return
;
}

else

{

for
(int i=;i<;i++)
{

int
nx = x+d[i][];
int
ny = y+d[i][];
if
(nx>&&nx<=n&&ny>&&ny<=m&&(map[nx][ny]=='.'||map[nx][ny]=='D'))
{

map[nx][ny]='X';
dfs(nx,ny,t-);
map[nx][ny]='.';
}
}
}

return
;
}

int
main()
{

int
t,num;
char
str[];
while
(scanf("%d%d%d",&n,&m,&t),n||m||t)
{

num=;
for
(int i=;i<=n;i++)
{

scanf("%s",str);
for
(int j=;j<=m;j++)
{

map[i][j]=str[j-];
if
(map[i][j]=='S')sx=i,sy=j;
else if
(map[i][j]=='D')ex=i,ey=j,num++;
else if
(map[i][j]=='.')num++;
}
}
flag=;
if
(num>=t)
dfs(sx,sy,t);
if
(flag==)
printf("NO\n");
else

printf("YES\n");
}

return
;
}
 

hdu1010 Tempter of the Bone(深搜+剪枝问题)的更多相关文章

  1. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  2. Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  3. hdu1010 Tempter of the Bone —— dfs+奇偶性剪枝

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Ja ...

  4. HDU 1010 Temper of the bone(深搜+剪枝)

    Tempter of the Bone Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) ...

  5. HDOJ/HDU Tempter of the Bone(深搜+奇偶性剪枝)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  6. Hdu1010Tempter of the Bone 深搜+剪枝

    题意:输入x,y,t.以及一个x行y列的地图,起点‘S’终点‘D’地板‘.’墙壁‘X’:判断能否从S正好走t步到D. 题解:dfs,奇偶性减枝,剩余步数剪枝. ps:帮室友Debug的题:打错了两个字 ...

  7. HDU1010 --- Tempter of the Bone(dfs+剪枝)

    小明做了一个很久很久的梦,醒来后他竟发现自己和朋友在一个摇摇欲坠的大棋盘上,他们必须得想尽一切办法逃离这里.经过长时间的打探,小明发现,自己所在的棋盘格子上有个机关,上面写着“你只有一次机会,出发后t ...

  8. Hdu3812-Sea Sky(深搜+剪枝)

    Sea and Sky are the most favorite things of iSea, even when he was a small child.  Suzi once wrote: ...

  9. HDU1010:Tempter of the Bone(dfs+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010   //题目链接 http://ycool.com/post/ymsvd2s//一个很好理解剪枝思想的博客 ...

随机推荐

  1. Kotlin Reference (八) Classes and Objects

    most from reference 类 Kotlin的类的声明使用关键字class class Invoice { } 类声明由类名.类头(指定其类型参数,构造函数等)和类体组成,由大括号括起来. ...

  2. [Python] 计算dataframe某一文本维度的平均长度

    print np.mean(df.title.apply(lambda x: len(x))) # 24.072694718 print df.title.apply(lambda x: len(x) ...

  3. HDU 1033

    http://acm.hdu.edu.cn/showproblem.php?pid=1033 这题的题干说的很绕,结合样例不难理解题意,走折线,A代表顺时针,V代表逆时针,给一个包含A和V的字符串,输 ...

  4. 使用tr1的bind函数模板

    最近把公司的VS2008统一升级为SP1了,虽然还是有些跟不上时代,毕竟C++17标准都出了,但是,对于成熟的商业软件开发而言,追求更新的C++标准肯定不是正道.升级SP1的VS2008可以支持TR1 ...

  5. vuex(三)actions

    actions:既然mutations只能处理同步函数,我大js全靠‘异步回调’吃饭,怎么能没有异步,于是actions出现了...   actions和mutations的区别     1.Acti ...

  6. BZOJ3444 最后的晚餐【细节题+组合数学】*

    BZOJ3444 最后的晚餐 Description [问题背景] 高三的学长们就要离开学校,各奔东西了.某班n人在举行最后的离别晚餐时,饭店老板觉得十分纠结.因为有m名学生偷偷找他,要求和自己暗恋的 ...

  7. sql中的一些函数(长期更新。。)

    前言 在最近看别人的sql的时候,看到一些函数,比如left(),right()等等,好奇是什么意思,查询之后觉得还是挺有用的,特此记录下来.博客会在遇到新的函数的时候定期更新. 正文 1. left ...

  8. ResultSet.TYPE_SCROLL_SENSITIVE到底发生了什么?

    转自:https://blog.csdn.net/axman/article/details/3984103 这个问题我在几年前说过,但今天再次从CSDN上看到有人问这个问题,可以看出,真正懂这个问题 ...

  9. python3 的字符串格式判断

    在python编程中,我们经常要面临将字符串进行转换的情况,那么字符串是否符合转换的要求呢?python中内置了字符串类的方法供我们使用进行字符串格式的判断. 1.isalnum() 所有字符都是数字 ...

  10. nginx 调试

    配置单进程非daemon方式启动 daemon off; master_process off;