题目: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 ≤ 10...
原创 2021-07-09 14:52:39
62阅读
BFS
转载 1月前
28阅读
#include <iostream> //poj 2243 Knight Moves 参照poj 1915#include <deque>using namespace std;int dir[2][8]={{-2,-1,1,2,2,1,-1,-2},{-1,-2,-2,-1,1,2,2,1}};int visited[10]
转载 2011-08-22 12:07:00
99阅读
2评论
public void bfs(boolean[]isVisited,int i){ int u;//表示队列的头结点对应的下标 int w;//表示邻接节点w //队列 LinkedList queue = new LinkedList(); //访问节点,输出节点信息 System.out.println(getValueByIndex(i)+"=>"); isVisited[i]=t.
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-digit room numbers on their offices. — It is a matter of sec...
原创 2021-07-09 14:52:37
57阅读
解决从某一状态到另一状态,状态很大 1.八数码https://www.acwing.com/problem/content/181/ 问最少步数将 23415x768 → 12345678x.九宫格移动,x为空格 #include<unordered_map> #define PII pair<in ...
转载 2021-07-24 15:09:00
91阅读
2评论
bfs的核心思想就是把一些问题抽象成图,从一个点开始,向四周开始扩散。一般使用队列这种数据结构,每次将一个节点周围所有节点加入队列。相较于dfs,bfs找到的路径一定是最短的,但代价就是空间复杂度比dfs大很多。从一个起点走到终点,问最短路径,这就是bfs的本质。下面为bfs大致模板int bfs(){ 初始化队列 初始化距离为-1 将起点距离设为0,并加入队列 while
转载 2021-09-25 20:27:00
89阅读
2评论
BFS & 双端BFS & A* & 双边BFS 1____广度优先搜索 1.1____什
转载 2021-07-25 19:31:00
119阅读
给一个n个点m条边(2 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #in...
转载 2015-09-25 11:31:00
70阅读
2评论
题目描述说好了,题目不黑人。给你一个8*8的矩阵,你的初始位置是左下角方格(用'U’表示),你的目标位置是右上角的方格(用'A'表示),其余的62个方格,如果是'.',表示这个方格为空,如果是'S',表示这个方格有一块大石头。好了现在你开始从左下角出发,每次可以往上,下,左,右,左上,右上,左下,右下移动一个方格,或者你可以原地不动,一共九个动作方式,在你做完一个动作后,所有的大石头会往下...
原创 2021-07-09 15:36:10
341阅读
题目:http://poj.org/problem?id=2243题意:给定一个8
原创 2017-08-18 10:25:09
26阅读
题目:http://poj.org/problem?id=1915题意:给定一个n∗n的棋盘,给定起点和终点,按照题相遇,这样可以减少一些搜索量,值得一提的
原创 2017-08-17 20:13:07
4阅读
Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start...
原创 2021-07-09 14:14:19
39阅读
You are given two pots, having the volume of A and B liters respectively. The following operations can be performed: FILL(i) fill the pot i (1 ≤ i ≤ 2
转载 2017-07-27 18:18:00
56阅读
题目大意: 给出n" role="presentation">nn(n" role="presentation">nn为3,5,7,9中的一个数)个在160至190的数字,每次可以把中间的数字放到最左边或最右边,求这个序列成为单调递增的最少次数。 Input" rol...
转载 2018-07-07 20:19:00
65阅读
2评论
直接上例题吧(md,刚刚写了一大堆,没保存wc,现在没心情了) 1 #include<bits/stdc++.h> 2 #define maxn 2010 3 using namespace std; 4 5 int l,n,sx,sy,mx,my,vis[maxn][maxn],dis[maxn] ...
转载 2021-10-02 16:02:00
101阅读
2评论
​​https://vjudge.net/problem/HDU-6223​​
转载 6月前
79阅读
433.Minimum Genetic MutationMedium26836FavoriteShareA gene string can be represented by an 8-character long string, with choices from"A","C","G","T".Suppose we need to investigate about a...
原创 6月前
48阅读
触的就是图的遍历算法,根据访问节点的顺序,可分为广度优先搜索(BFS)和深度优先搜索(DFS)。广度优先搜索(BFS
转载 1月前
21阅读
  • 1
  • 2
  • 3
  • 4
  • 5