
深度优先搜索/广度优先搜索
深度优先搜索/广度优先搜索
Wanidde
本人很懒,什么都没有留下 ^_^
展开
-
广度优先搜索(宽度优先搜索)迷宫问题
使用队列,层层递进,往下扩展。 5 4 0 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 4 3(5,4是迷宫的行和列,0代表空地,1代表障碍物,1,1是起始位置,4,3 是需要到达的位置) 7 #include<stdio.h>struct no...原创 2018-07-16 16:20:40 · 3294 阅读 · 1 评论 -
POJ 3009 - Curling 2.0 ( DFS )
Curling 2.0Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 27947 Accepted: 11108 DescriptionOn Planet MM-21, after their Olymp...原创 2019-01-26 12:22:07 · 228 阅读 · 0 评论 -
算法7-4,7-5:图的遍历——深度优先搜索
题目描述深度优先搜索遍历类似于树的先根遍历,是树的先根遍历的推广。其过程为:假设初始状态是图中所有顶点未曾被访问,则深度优先搜索可以从图中的某个顶点v出发,访问此顶点,然后依次从v的未被访问的邻接点出发深度优先遍历图,直至图中所有和v有路径相通的顶点都被访问到;若此时图中尚有顶点未被访问,则另选图中一个未曾被访问的顶点作为起始点,重复上述过程,直至图中所有顶点都被访问到为止。其算法可以描述...原创 2018-05-15 16:25:16 · 1948 阅读 · 0 评论 -
算法7-6:图的遍历——广度优先搜索
题目描述广度优先搜索遍历类似于树的按层次遍历的过程。其过程为:假设从图中的某顶点v出发,在访问了v之后依次访问v的各个未曾被访问过的邻接点,然后分别从这些邻接点出发依次访问它们的邻接点,并使“先被访问的顶点的邻接点”先于“后被访问的顶点的邻接点”被访问,直至图中所有已被访问的顶点的邻接点都被访问到。若此时图中尚有顶点未被访问,则另选图中一个未曾被访问的顶点作为起始点。重复上述过程,直至图中所有...原创 2018-05-16 14:49:38 · 1216 阅读 · 0 评论 -
ZOJ 2412 - Farm Irrigation ( dfs )
Farm IrrigationBenny has a spacious farm land to irrigate. The farm land is a rectangle, and is divided into a lot of samll squares. Water pipes are ...原创 2019-01-20 12:44:58 · 148 阅读 · 0 评论 -
UVA 439 - Knight Moves (bfs)
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find theshortest closed tour of knight moves that visits each square of a given set of n squares on a chessbo...原创 2019-01-18 17:19:00 · 212 阅读 · 0 评论 -
HDU 1253 - 胜利大逃亡 ( dfs )
Ignatius被魔王抓走了,有一天魔王出差去了,这可是Ignatius逃亡的好机会.魔王住在一个城堡里,城堡是一个A*B*C的立方体,可以被表示成A个B*C的矩阵,刚开始Ignatius被关在(0,0,0)的位置,离开城堡的门在(A-1,B-1,C-1)的位置,现在知道魔王将在T分钟后回到城堡,Ignatius每分钟能从一个坐标走到相邻的六个坐标中的其中一个.现在给你城堡的地图,请你计算出Ig...原创 2018-08-16 11:25:40 · 309 阅读 · 0 评论 -
关于搜索(DFS 、BFS)
深度优先搜索(DFS): 思想: 首先以一个未被访问过的顶点作为开始顶点,沿当前顶点的边走到未访问过的顶点;当没有未访问过的顶点时,则回溯到上一个顶点,继续试探访问别的顶点,直到所有的顶点都被访问过。完整代码:#include<stdio.h>int a[10],book[10],n;void dfs(int step){ int ...原创 2018-07-21 16:09:38 · 240 阅读 · 0 评论 -
HDU 2717 - Catch That Cow (BFS)
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,000) on a number line and the cow is at a point K (0 ≤ K ≤ 100,0...原创 2018-07-20 17:43:45 · 214 阅读 · 0 评论 -
深度优先搜索
#include<stdio.h>int a[10],book[10],n;void dfs(int step){ int i; if(step == n+1) { for(i = 1;i <= n;i ++) printf("%d",a[i]); printf("\n"); return; } for(i = 1;i <= n;i ++...原创 2018-07-15 10:49:58 · 217 阅读 · 0 评论 -
HDU 1242 - Rescue (bfs)
Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M <= 200) matrix. There are WALLs, ROADs, and GUARDs in the prison.Angel's friends want to...原创 2018-07-20 16:23:33 · 182 阅读 · 0 评论 -
HDU 1548- A strange lift (DFS)
There is a strange lift.The lift can stop can at every floor as you want, and there is a number Ki(0 <= Ki <= N) on every floor.The lift have just two buttons: up and down.When you at floor i,if...原创 2018-07-17 16:17:38 · 195 阅读 · 0 评论 -
HDU 1016- Prime Ring Problem (DFS)
A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of numbers in two adjacent circles should be a prime.Note: the number of f...原创 2018-07-17 16:01:06 · 117 阅读 · 0 评论 -
HDU1312 - Red and Black (DFS)
There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can'...原创 2018-07-16 19:41:34 · 192 阅读 · 0 评论 -
HDU1241 - Oil Deposits (DFS)
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides th...原创 2018-07-16 17:51:12 · 381 阅读 · 0 评论 -
HDU1010-Tempter of the Bone(DFS)
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 ...原创 2018-07-16 17:43:53 · 158 阅读 · 0 评论 -
HDU 1026 - Ignatius and the Princess I(BFS优先队列)
Ignatius and the Princess ITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23283Accepted Submission(s): 7554Speci...原创 2019-04-03 15:42:23 · 241 阅读 · 0 评论