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. (?m)使用实例

    示例sql: # User@Host: zjzc_app[zjzc_app] @ [10.22.18.164] Id: 6069153 # Query_time: 153.908486 Lock_ti ...

  2. Amazon Redshift and Massively Parellel Processing

    Today, Yelp held a tech talk in Columbia University about the data warehouse adopted by Yelp. Yelp u ...

  3. kindeditor在sae上传文件修改,适合php

    kindeditor在sae上传文件修改,适合php 当前位置: 首页  > 论坛  > 经验共享 用户登录   新用户注册   主题: kindeditor在sae上传文件修改,适合ph ...

  4. 1 游戏逻辑架构,Cocos2d-x游戏项目创建,HelloWorld项目创建,HelloWorld程序分析,(CCApplicationProtocol,CCApplication,AppDeleg

     1 游戏逻辑架构 具体介绍 A 一个导演同一时间仅仅能执行一个场景,场景其中,能够同一时候载入多个层,一个层能够可载多个精灵.层中亦能够加层. B  场景切换 sceneàaddChild(la ...

  5. Bestcoder HDU5059 Help him 字符串处理

    Help him Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  6. 【Java基础】构造方法调用构造方法

    从一个程序开始: class dog { private String name; private String color; private int age; dog(String name) // ...

  7. eclipse.ini内存设置

    这两天用eclipse,突然变得很卡,就上网找了些资料,对eclipse.ini启动参数配置,整理如下: 1.先了解下JVM内存管理机制,JVM内存分为堆内存和非堆内存 2.JVM内存限制 首先JVM ...

  8. Eclipse关联Java源代码

    一个很简单的技巧,不多说,直接贴图 1. 2 . 3.选择你jdk下的src.zip就可以了.搞定!

  9. java中List的用法

    list的添加删除等操作 import java.util.*; class TestList { public static void main(String[] args) { List<S ...

  10. C#获取本机IP方法,获取本机局域网IP地址方法

    1. private void GetIP() { string hostName = Dns.GetHostName();//本机名 //System.Net.IPAddress[] address ...