hdu 1010 Tempter of the Bone 深搜+剪枝
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
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 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.
#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 深搜+剪枝的更多相关文章
- HDU 1010 Temper of the bone(深搜+剪枝)
Tempter of the Bone Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) ...
- 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 ...
- hdu1010 Tempter of the Bone(深搜+剪枝问题)
Tempter of the Bone Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission( ...
- HDU 1010 Tempter of the Bone(深度+剪枝)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 题意:就是给出了一个迷宫,小狗必须经过指定的步数到达出口,并且每个格子只能走一次. 首先先来介绍一下奇偶性 ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- HDU 1010 Tempter of the Bone (DFS+剪枝)
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...
- hdu 1010 Tempter of the Bone (奇偶性剪枝)
题意:有一副二维地图'S'为起点,'D'为终点,'.'是可以行走的,'X'是不能行走的.问能否只走T步从S走到D? 题解:最容易想到的就是DFS暴力搜索,,但是会超时...=_=... 所以,,要有其 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
随机推荐
- C# 反射_基础
反射用于在程序运行过程中,获取类里面的信息或发现程序集并运行的一个过程.通过反射可以获得.dll和.exe后缀的程序集里面的信息.使用反射可以看到一个程序集内部的类,接口,字段,属性,方法,特性等信息 ...
- Cocos2d-x 2.1.5 简单动画
Cocos2d新版本函数更改了一些. 下面的代码可以产生一个简单动画. //第一步:生成动画需要的数据 CCTexture2D *texture=CCTextureCache::sharedTextu ...
- POJ 2533 Longest Ordered Subsequence - from lanshui_Yang
题目大意:求一个数列的最长上升子序列(严格上升). 解题思路: 方法一:O(n^2) dp[i]:表示处理到第i个位置,序列的最长上升子序列末尾为i的长度: a[]数组存储原序列 dp[i] = ma ...
- sh里没有多行注释,只能每一行加一个#号
sh里没有多行注释,只能每一行加一个#号.只能像这样: #-------------------------------------------- # 这是一个自动打ipa的脚本,基于webfrogs ...
- 【转】 linux内核移植和驱动添加(三)
原文网址:http://blog.chinaunix.net/uid-29589379-id-4708909.html 原文地址:linux内核移植和驱动添加(三) 作者:genehang 四,LED ...
- python定时器爬取豆瓣音乐Top榜歌名
python定时器爬取豆瓣音乐Top榜歌名 作者:vpoet mail:vpoet_sir@163.com 注:这些小demo都是前段时间为了学python写的,现在贴出来纯粹是为了和大家分享一下 # ...
- iOS SDK原生JSON解析
- (IBAction)touchReadButton:(id)sender { NSData *jsonData = [[NSData alloc] initWithContentsOfFile:J ...
- [每日一题] OCP1z0-047 :2013-08-18 禁用启用约束――主键与外键 ..................................61
正确答案:C 根据题意,测试结果如下: 1.创建表emp,并且设emp_no字段为主键,设mgr_no字段为外键. gyj@MYDB> create table emp 2 (emp_no nu ...
- LR实战之Discuz开源论坛——安装及简介
想了很久,也许是因为这段时间特别闲,从毕业到现在,我的测试职业生涯也近两年了,发现自己越来越喜欢测试领域,也越来越偏向测试开发了,作为一名专业的测试人员,不得不要学习性能测试,而使用LoadRunne ...
- jqGrid插件的重载表格的解决方案
jqGrid插件的重载表格的解决方案 $("#table_list_1").empty();// 清空表格内容 var parent=$("#gbox_table_lis ...