hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 82702 Accepted Submission(s): 22531
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<stdio.h>
#include<string.h>
int n , m , T ;
bool vis[][] , flag;
char map[][] ;
int move[][] = {{,} , {-,} , {,} , {,-}} ;
int step = ; void dfs (int sx , int sy , int step )
{
if (step == T + && map[sx][sy] == 'D') {
flag = ;
return ;
}
// printf ("(%d,%d) %c step=%d\n" , sx , sy , map[sx][sy] , step) ;
if (map[sx][sy] == 'D') return ;
if (step > T) return ;
for (int i = ; i < ; i ++) {
int x , y ;
x = sx + move[i][] ;
y = sy + move[i][] ;
if (x < || y < || x >= n || y >= m) continue ;
if (map[x][y] == 'X') continue ;
if (vis[x][y]) continue ;
vis[x][y] = ;
dfs (x , y , step + ) ;
if (flag) return ;
vis[x][y] = ;
}
} int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d%d%d" , &n , &m , &T)) {
if (n == &&m == && T == ) break ;
for (int i = ; i < n; i ++) scanf ("%s" , map[i]) ;
flag = ;
step = ;
memset (vis , , sizeof(vis)) ;
for (int i = ; i < n; i ++) {
for (int j = ; j < m ; j ++) {
if (map[i][j] == 'S') {
vis[i][j] = ;
dfs (i , j , ) ;
}
}
}
if (flag) puts ("YES") ;
else puts ("NO") ;
}
return ;
}
这道题是要奇偶剪枝的,但我没剪也过了。(虽说压线,23333333333333333)
转载:http://www.2cto.com/kf/201307/229103.html
hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)的更多相关文章
- 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
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- HDU 1010 Tempter of the Bone (DFS+可行性奇偶剪枝)
<题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了 #include<cstdio> #include<stdio.h> #include<cstdlib> #include ...
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...
随机推荐
- 帝国cms实现会员注册之后根据所在会员组转向的方法
帝国cms要实现会员注册之后根据所在会员组转向的能能,就需要修改/e/member/class/member_registerfun.php文件找到第175行,修改成如下代码: //审核 if($ch ...
- Visual Studio 2013小技巧
Ctrl + F10 可以直接运行到光标处,而不用F10 逐过程 F11 逐语句了 当有多个断点时,按F5可以切换到下一个断点.
- SQL查询效率:100w数据查询只需要1秒钟
G os: windows 数据库: ms sql server 目的: 查询性能测试,比较两种查询的性能 SQL查询效率 step by step -- setp . -- 建表 create ta ...
- 访问cv::Mat中的数据时遇到的指针类型问题
在用Opencv的时候由于下图原本的图像尺寸是1111*1111,要进行resize,代码如下: cv::Mat img = cv::imread("//Users//apple//td3/ ...
- electron打包
1.全局安装electron-packager npm install -g electron-packager 2.在项目目录下执行命令 electron-packager ./ --platfor ...
- 仿照jquery封装一个自己的js库(一)
所谓造轮子的好处就是复习知识点,加深对原版jquery的理解. 本文系笔者学习jquery的笔记,记述一个名为"dQuery"的初级版和缩水版jquery库的实现.主要涉及知识点包 ...
- hdu 1873 看病要排队(优先级队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1873 题目大意: 三个医生看病,病人排队看病,病人有优先级,优先级高的提前看病,同样的优先级按先后.I ...
- asp.net+mysq 数据库操作类
对数据库操作的使用方法: 1.引入命名空间 2.操作.三四行代码即可完成数据操作.类似于: using System; using System.Data; using System.Text; us ...
- MSSQL数据库索引的应用
一.索引的概念 索引就是加快检索表中数据的方法.数据库的索引类似于书籍的索引.在书籍中,索引允许用户不必翻阅完整个书就能迅速地找到所需要的信息.在数据库中,索引也允许数据库程序迅速地找到表中的数据,而 ...
- C# 获取进程或线程的相关信息
信息来自: http://blog.163.com/kunkun0921@126/blog/static/169204332201293023432113/ using System; using S ...