Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 55541    Accepted Submission(s): 14983 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 146511    Accepted Submission(s): 39059 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
  如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释: 这种方案学名为“奇偶剪枝”.我们已知了最短的步数就是直角三角形的两条直角边,实际上的路径却不一定非要沿着这两条边走的.仔细看看只要是移动方向一直是右.下,那么走到的时候总步数也一定是path的.然而由于墙的存在或许我们不可能一直右.下的走下去.为了避开墙,我们可能会向左走,向上走等等.但为了到达目的地…
//我刚开始竟然用bfs做,不断的wa,bfs是用来求最短路的而这道题是求固定时间的 //剪纸奇偶剪枝加dfs #include<stdio.h> #include<queue> #include<math.h> #include<string.h> using namespace std; #define N 10 char ma[N][N]; struct node { int x,y,step; }ss,tt; int dis[4][2]={1,0,-…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58766    Accepted Submission(s): 15983 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 125945    Accepted Submission(s): 33969 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 149833    Accepted Submission(s): 39945 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四类元素组成. S'代表是开始位置: 'D'表示结束位置:'.'表示可以走的路:'X'表示是墙. 问:从‘S’  能否在第 t 步 正好走到 'D'. 解题思路: 平常心态做dfs即可,稍微加个奇偶剪枝,第一次做没经验,做过一次下次就知道怎么做了.最后有代码注释解析. AC Code: #includ…
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 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
学习链接:http://www.ihypo.net/1554.html https://www.slyar.com/blog/depth-first-search-even-odd-pruning.html http://blog.csdn.net/chyshnu/article/details/6171758 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题解:刚开始写直接超时,还没学剪枝,奇偶剪枝... 关于奇偶剪枝 首先举个例子,有…
<题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要在某一时刻到达,所以需要用到可行性剪枝中的奇偶剪枝,如果在某一点,它所剩的步数与到终点的最短距离之差是偶数,说明这种情况有可能恰好在规定时刻到达终点,否则不可能,将其剪去. #include <bits/stdc++.h> using namespace std; ][]; ][]; int n,…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89317    Accepted Submission(s): 24279 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 144191    Accepted Submission(s): 38474 Problem Description The doggie fou…
题目链接:  http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意:给定起点和终点,问刚好在t步时能否到达终点. 解题思路: 4个剪枝. ①dep>t剪枝 ②搜到一个解后剪枝 ③当前走到终点最少步数>满足条件还需要走的步数剪枝(关键) ③奇偶剪枝(关键):当前走到终点步数的奇偶性应该与满足条件还需要走的步数奇偶性一致. 其中三四两步放在一步中写:remain=abs(x-ex)+abs(y-ey)-abs(dep-t) 奇偶剪枝的原理:abs(…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 92175    Accepted Submission(s): 25051 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 135529    Accepted Submission(s): 36393 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 d…
Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 doggi…
题目链接:pid=1010">点击打开链接 题目描写叙述:给定一个迷宫,给一个起点和一个终点.问是否能恰好经过T步到达终点?每一个格子不能反复走 解题思路:dfs+剪枝 剪枝1:奇偶剪枝,推断终点和起点的距离与T的奇偶性是否一致,假设不一致,直接剪掉 剪枝2:假设从当前到终点的至少须要的步数nt加上已经走过的步数ct大于T,即nt+ct>t剪掉 剪枝3:假设迷宫中能够走的格子小于T直接剪掉 启示:剪枝的重要性 代码: #include <cstdio> #include…
题意: 必须在第t秒走到格子D上,S为起点,D为终点,点就是可以走,X就是墙. 思路: 将迷宫外围四面都筑墙‘X’.深度搜索+奇偶剪枝,再加一个剪枝“无法在指定时间内到达”. #include <iostream> #include <vector> #include <string> #include <math.h> using namespace std; vector<string> v; int n,m; int x_1,y_1,x_2…
剪枝是什么,简单的说就是把不可行的一些情况剪掉,例如走迷宫时运用回溯法,遇到死胡同时回溯,造成程序运行时间长.剪枝的概念,其实就跟走迷宫避开死胡同差不多.若我们把搜索的过程看成是对一棵树的遍历,那么剪枝顾名思义,就是将树中的一些“死胡同”,不能到达我们需要的解的枝条“剪”掉,以减少搜索的时间. 这里介绍一下奇偶剪枝 什么是奇偶剪枝? 部分内容来自https://blog.csdn.net/chyshnu/article/details/6171758 把矩阵看成如下形式:  0 1 0 1 0…
转载大佬的blog,很详细,学到了很多东西 奇偶剪枝:根据题目,dog必须在第t秒到达门口.也就是需要走t-1步.设dog开始的位置为(sx,sy),目标位置为(ex,ey).如果abs(ex-x)+abs(ey-y)为偶数,则abs(ex-x)和abs(ey-y)奇偶性相同,所以需要走偶数步: 当abs(ex-x)+abs(ey-y)为奇数时,则abs(ex-x)和abs(ey-y)奇偶性不同,到达目标位置就需要走奇数步.先判断奇偶性再搜索可以节省很多时间,不然的话容易超时.t-sum为到达目…
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 despe…
Tempter of the Bone 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…
转载声明:原文转自:http://www.cnblogs.com/xiezie/p/5568822.html 第一次遇到迷宫搜索,给我的感觉是十分惊喜的:搞懂这个的话,感觉自己又掌握了一项技能~ 个人感觉,角色扮演类的游戏,起码都可以在迷宫搜索上找到影子. 奇偶剪枝这个算法感觉十分开阔的视野~这样去描述这个具体问题实在太形象生动了~ 总而言之,十分有趣. 仔细的人会发现  每当设计到移动,我们必须想到上下左右,这也让我们看到这类算法的思路. 在学习迷宫搜索当中,我发现:这个搜索算法是先分析 找到…
题目: 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 ou…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:根据地图,'S'为开始位置,'D'为门的位置,' . '为空地,'X'为墙,不能经过,问:在指定的时间,是否能到达'门'的位置.注意:路不可以重复经过,时间也要刚好是 t ,不能少. 思路: 此处不能用BFS,因为时间要恰好为t,还是得用DFS,不过需要剪枝才能过. 奇偶剪枝: 从一个点到达另外一个点的最短路径长度(时间)可以根据两点坐标求出,路径长度(非最短)与最短路径的长度同奇…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 151082    Accepted Submission(s): 40265 Problem Description The doggie found a bone in an ancient maze, which fascinated him…
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 107043    Accepted Submission(s): 29107 Problem Description The doggie found a bone in an ancient maze, which fascinated him a…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目描述:在n*m的矩阵中,有一起点和终点,中间有墙,给出起点终点和墙,并给出步数,在该步数情况下走到终点,走过的点不能再走: 题目要点:dfs+奇偶剪枝:输入: 本题用dfs可以做出结果,但是会超时,需要用到就剪枝,来减去大部分的可能: 奇偶剪枝: 方格中起点(tx,ty)和终点(dx, dy)最小步骤是minstep=abs(tx-dx)+abs(ty-dy); 给定步数t,从起点走到终点…