Tempter of the Bone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 88774    Accepted Submission(s): 24159

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 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
 
题意:从起点到终点,要求恰好在时间t到达。若能输出YES,反之,NO;
思路:一开始想着用BFS后来发现BFS求的是最短路径。有可能在不能恰好到达。改成DFS回溯加剪枝。
         2.字符读入,每行都有换行需要用getchar()过滤掉。
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
#define maxn 50
int n,m,t,flag;
struct Node
{
int x,y;
};
Node st,et,k;
int dx[]={,,-,};
int dy[]={,-,,};
int vis[maxn][maxn];
char map[maxn][maxn];
void dfs(int x,int y,int cost)
{
if(flag==)
return;
if(map[x][y]=='D'&&cost==t)//目标状态:步数为,坐标位置为D;
{
flag=;
return;
}
int mindis=abs(x-et.x)+abs(y-et.y); /*当前点到终点的最短距离*/
if(mindis>t-cost||( t-cost-mindis )%!=)
return;//奇偶剪枝
for(int i=;i<;i++)//扩展方式:上下左右;
{
int nx=x+dx[i];
int ny=y+dy[i];
if(!vis[nx][ny]&&nx>=&&nx<n&&ny>=&&ny<m&&map[nx][ny]!='X')
{
//printf("%d %d %d\n",nx,ny);
vis[nx][ny]=;
dfs(nx,ny,cost+);
vis[nx][ny]=;
} } } int main()
{
while(~scanf("%d%d%d",&n,&m,&t))
{
if(n==||m==||t==)
break;
getchar();
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
{
st.x=i;
st.y=j;
}
if(map[i][j]=='D')
{
et.x=i;
et.y=j;
} }
getchar();
}
flag=;
memset(vis,,sizeof(vis));
vis[st.x][st.y]=;
dfs(st.x,st.y,);//初始状态:S的位置坐标,步数为0;
if(!flag)
printf("NO\n");
else
printf("YES\n"); } return ;
}

hdu 1010 Tempter of the Bone 深搜+剪枝的更多相关文章

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

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

  2. 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 ...

  3. hdu1010 Tempter of the Bone(深搜+剪枝问题)

    Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...

  4. HDU 1010 Tempter of the Bone(深度+剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...

  5. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

  6. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

  7. HDU 1010 Tempter of the Bone (DFS+剪枝)

    题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...

  8. hdu 1010 Tempter of the Bone (奇偶性剪枝)

    题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...

  9. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

随机推荐

  1. Wpf中MediaElement循环播放

    原文:Wpf中MediaElement循环播放 前一段时间做了一个项目,里面牵涉到媒体文件的循环播放问题,在网上看了好多例子,都是在xaml中添加为MediaElement添加一个TimeLine,不 ...

  2. 【转】Android下编译jni库的二种方法(含示例) -- 不错

    原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从N ...

  3. UESTC_温泉旅店 CDOJ 878

    天空飘下一朵一朵的雪花,这是一片纯白的世界. 在天空之下的温泉旅店里,雪菜已醉倒在一旁,冬马与春希看了看说着梦话的雪菜,决定找一点玩的来度过这愉快的晚上. 这家旅店提供一种特色游戏,游戏有n张牌,各写 ...

  4. Restful风格的springMVC配搭ajax请求的小例子

    1. GET请求的例子 ajax代码: 请求参数拼接在url后面(参数在服务器可通过HttpServletRequest获取,也可以直接通过@RequestParam自动注入,参考DELETE例子的方 ...

  5. kettle工具二次开发-代码启动JOB

    kettle工具是一款优秀的数据同步.数据处理的BI工具,收到了很多人的青睐.kettle软件通过可视化的图标可以让我们很轻易的能完成数据同步.处理的开发工作.但是使用kettle可视化界面在跑JOB ...

  6. 图解MapReduceMapReduce整体流程图

    1.图解MapReduceMapReduce整体流程图 并行读取文本中的内容,然后进行MapReduce操作 Map过程:并行读取三行,对读取的单词进行map操作,每个词都以<key,value ...

  7. js执行环境深入研究

    js 声明函数是创建函数对象的过程,当创建函数对象时,函数对象的[[scope]] =连当前执行环境对象的作用域(栈顶执行环境--当执行函数时,js会将该函数的执行环境对象入栈) 当为全局函数时,如: ...

  8. url 的httppost 和http get ,put,delect

    URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源 ,而HTTP中的GET,POST,PUT,DELETE就对应着对这个资源的查 ,改 ,增 ,删 4个操作 .到这里 ...

  9. 使用react-native做一个简单的应用-01项目介绍

    学习react-native也有一个月的时间了.当学习了关于react-native的基础知识之后,打算自己去仿一个应用去练手.于是花了10天左右的时间,这个小应用的基本功能也实现的差不多了. 在展示 ...

  10. Android 创建自定义布局

    我们所有的控件都是继承至View类的,而所有的布局都是继承至ViewGroup的,所以我们也可以继承某个view类来实现我们自己的布局或者控件. 引入布局 我们新建一个title.xml的layout ...