hdoj 1010-Tempter of the Bone
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.
'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.
S.X.
..X.
..XD
....
3 4 5
S.X.
..X.
...D
0 0 0
YES
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace::std; int N,M,T,t;
char maps[][];
int maps_[][];
int stx,sty,enx,eny;
int a[][] = {{,},{-,},{,},{,-}};
bool dfs(int n,int m)
{
if( n == enx && m == eny && t == T )
{
return true;
} int ans = T-t-abs(enx-n)-abs(eny-m); //奇偶剪枝,感觉好吊。
if(ans< || ans&)
return false; for(int i = ;i<;i++)
{
int x = n + a[i][];
int y = m + a[i][];
if(maps[x][y] != 'X' && maps_[x][y] != && x>= && y>= && x<N && y<M)
{
t++;
maps_[x][y] = ; if(dfs(x,y))
return true;
else{
t--;
maps_[x][y] = ;
} }
}
return false;
}
int main()
{
while(scanf("%d %d %d",&N,&M,&T) && N != )
{
memset(maps,,sizeof(maps)); //每次输入把地图和标记清空
memset(maps_,,sizeof(maps_));
for(int i=; i<N; i++)
{
scanf("%s",&maps[i]);
for(int j = ; j<M;j++)
{
if(maps[i][j] == 'S') //起始点
{
stx = i;
sty = j;
}
else if(maps[i][j] == 'D') //终点
{
enx = i;
eny = j;
}
}
}
t = ;
maps_[stx][sty] = ; //标记起点
if(dfs(stx,sty))
{
printf("YES\n");
}else
printf("NO\n");
}
return ;
}
hdoj 1010-Tempter of the Bone的更多相关文章
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- 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 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- 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 ...
- hdu 1010 Tempter of the Bone 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
- 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 ...
- 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 ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 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 ...
随机推荐
- vue使用vuex大体结构
store1.js const state = {} const mutations = {} const actions = {} const getters = {} export default ...
- js 删除 数组中某个元素(转载)
来源:https://www.jb51.net/article/134312.htm js删除数组中某一项或几项的几种方法 https://www.jb51.net/article/154737.ht ...
- java线程的生命周期及五种基本状态
一.线程的生命周期及五种基本状态 关于Java中线程的生命周期,首先看一下下面这张较为经典的图: 上图中基本上囊括了Java中多线程各重要知识点.掌握了上图中的各知识点,Java中的多线程也就基本上掌 ...
- CRM-Modelformset
CRM-Modelformset 效果图 利用modelformset实现上面的效果: views.py文件: from user.formself.myform import RegForm, Cu ...
- Android笔记(四十九) Android中的资源访问——asset
1.文件读取方式 AssetManager.open(String filename),返回的是一个InputSteam类型的字节流,这里的filename必须是文件,而不能是文件夹, ...
- php初识2
php概述 什么是php,PHP语言的优势,PHP5的新特性,PHP的发展趋势,PHP的应用领域. PHP是超文本预处理器,是一种服务器端,跨平台,HTML嵌入式的脚本语言,具有c语言,Java语言, ...
- 设置Django生产环境系统重启后的自动启动项
前面,作者已经介绍了把Django部署到生产环境中的主要方法,现在我们来看一下如何设置项目开机启动. 在把Django项目部署到生产环境中时,我们前面使用安装包和源码安装了Nginx.uwsgi.re ...
- 资源管理与调度系统-YARN资源隔离及以YARN为核心的生态系统
资源管理与调度系统-YARN资源隔离及以YARN为核心的生态系统 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是资源隔离 资源隔离是指为不同任务提供可独立使用的计算资源以 ...
- 2013.6.22 - OpenNE第二天
果然看中文材料就比较顺利,才半个小时就看完了一篇非常简单的综述<命名实体识别研究进展综述>(孙镇.王惠临).这个是2010年的文章,其实就是一个 科普文章,简述了国内外NER这块的历史如何 ...
- 关于MQ的几件小事:如何保证消息队列的高可用
原文:https://www.cnblogs.com/jack1995/p/10908797.html 1.RabbitMQ的高可用 RabbitMQ基于主从模式实现高可用.RabbitMQ有三种模式 ...