Tempter of the Bone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 93821    Accepted Submission(s): 25482

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
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:  1072 1312 1026 1240 1175

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char map[10][10];
int vis[10][10];
int dx[4]={1,0,0,-1};
int dy[4]={0,1,-1,0};
int m,n,t,flog;
int sx,sy,ex,ey;
void dfs(int x,int y,int l)
{
if(flog)
return ;
if(map[x][y]=='D'&&l==t)
{
flog=1;
return ;
}
int temp=t-abs(ex-x)-abs(ey-y)-l;//当前的位置到达终点的最短距离
if(temp<0||temp&1)
return ;
for(int i=0;i<4;i++)
{
int nx=x+dx[i];
int ny=y+dy[i];
if(nx>=0&&ny>=0&&nx<n&&ny<m&&!vis[nx][ny]&&map[nx][ny]!='X'&&l+1<=t)
{
vis[nx][ny]=1;
dfs(nx,ny,l+1);
vis[nx][ny]=0;
}
}
}
int main()
{
while(scanf("%d%d%d",&n,&m,&t),m||n||t)
{
int w=0;
memset(map,'\0',sizeof(map));
for(int i=0;i<n;i++)
{
scanf("%s",map[i]);
for(int j=0;j<m;j++)
{
if(map[i][j]=='S')
sx=i,sy=j;
if(map[i][j]=='D')
ex=i,ey=j;
if(map[i][j]=='X')
w++;
}
}
memset(vis,0,sizeof(vis));
vis[sx][sy]=1;
flog=0;
// if(t<n*m-w)
dfs(sx,sy,0);
if(flog)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

hdoj--1010--Tempter of the Bone(搜索+奇偶剪枝)的更多相关文章

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

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

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

  3. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...

  4. hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】

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

  5. Tempter of the Bone(dfs奇偶剪枝)

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

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

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

  7. M - Tempter of the Bone(DFS,奇偶剪枝)

    M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

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

    学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.h ...

  9. Tempter of the Bone 搜索---奇偶性剪枝

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

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

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

随机推荐

  1. 英语发音规则---N字母

    英语发音规则---N字母 一.总结 一句话总结: 1.位于词尾的n在m后面时不发音? autumn /'ɔːtəm/ n. 秋天 column /'kɒləm/ n. 纵队 2.在音素/k//g/前面 ...

  2. 7.matlab字符串分析

    1 字符串处理函数 clc; clear all; str='My name is Robin.'; disp(str); %字符串的输出 str_size=size(str) %字符串的长度 str ...

  3. 在ubuntu下安装zookeeper

    安装java环境,并配置好java相关的环境变量$JAVA_HOME. 1.下载并解压最新稳定的zookeeper文件 wget http://mirrors.cnnic.cn/apache/zook ...

  4. EF Code First 使用 代码优先迁移(三)

    迁移到特定版本(包括降级) 到目前为止,我们一直升级到最新的迁移,但有时您可能需要升级/降级到特定的迁移. 这是目前我数据库中的表:有四个表,我降级到addEndTime这个版本(这个版本是没有gra ...

  5. javascript一个重要知识点:事件。

    javascript是事件驱动的,那什么是事件?事件就是在javascript中被侦测到DOM元素行为,就称之为javascript事件. 2.事件的三个阶段 事件的三个阶段分别为: 1.捕获阶段 2 ...

  6. 实现点击EditText登录时,界面上移避免键盘遮挡界面

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&quo ...

  7. Stack Overflow大揭密:哪一种程序员工资最高?

    Stackoverflow在程序员之间可以說是无人不知无人不晓,甚至常有人开玩笑说:“如果stackoverflow倒闭了,全世界代码的产出率将下降一半以上”或许听起来有点夸张,但是不难想像这个网站在 ...

  8. NSRunloop总结

    NSRunloop是一个消息处理机制:是一个循环. 系统通过消息队列和runloop与进程(线程)通信. runloop是一个机制和体系结构. 它包含以下几个方面: 1.事件源管理: 2.事件的检索与 ...

  9. 【AnjularJS系列5 】— scopes、module、controller

    第五篇, scopes.module.controller 这一篇,感觉,在前面几篇就使用过的属性,但,总觉得没有理解透彻,有待完善!~ 1.scopes A.定义:$scope是一个把view(一个 ...

  10. Pyhton学习——Day29

    #异常与错误# 什么是异常?# 异常就是程序运行时发生错误的信号,在程序出现错误时,则会产生异常,若没有程序处理,则会抛出异常# 导致程序在异常语句处崩溃终止# Traceback 追踪异常信号:** ...