![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
BFS
-skyline-
这个作者很懒,什么都没留下…
展开
-
Knight Moves HDU - 1372 (BFS)
题意: 棋盘(a-h)*(1-8),输入起始位置,和终点位置,输出,骑士至少走几步可以从起始位置到达终点位置。(骑士走路方式和马走日一致) 思路: BFS 注意字母表示列,数字表示行。 代码: #include<bits/stdc++.h> using namespace std; const int N=505; int dir[][2]={ -1,-2, ...原创 2020-04-10 18:18:39 · 193 阅读 · 0 评论 -
2018 ICPC 焦作现场 F. Honeycomb(BFS求最短路,卡memset)
题意: 给一个蜂巢图,问从s到t最短路径长是多少。 思路: BFS。 1. 每个格子相邻的有六个格子,所以每步能走六个方向,把六个方向的坐标看好。 2. 不要用vis[][]记录走过与否,memset会超时,直接在原图上标记! 代码: #include<bits/stdc++.h> using namespace std; //Life is Short! const...原创 2020-04-09 23:37:27 · 240 阅读 · 0 评论 -
Asteroids! HDU - 1240 三维BFS
#include<bits/stdc++.h> using namespace std; //Life is Short! char a[15][15][15];//zxy bool vis[15][15][15]; struct node{ int x,y,z; int step; }s,t; int dir[][3]={ 0,0,1, 0,0,-1...原创 2020-04-09 11:26:02 · 97 阅读 · 0 评论 -
Labyrinth CodeForces - 1063B (BFS 标特殊记)
题意:一张n*m得网格图,有障碍物,起点是(r,c),每步能向上、下、左、右中的某个方向走一格,向左走不能超过x步,向右走不能超过y步,问从起点可以到达格数? 思路:设一个tag类型的vis[][]标记,tag的结构体里有l、r两个属性,走到 (x,y) 这一格时,vis[x][y].l 表示已经向左走了多少步,vis[x][y].r 表示已经向右走了多少步,如果l r都是-1,表示这格还没访问...原创 2019-10-01 16:33:22 · 202 阅读 · 0 评论 -
Olya and Energy Drinks CodeForces - 877D(BFS+剪枝)
题目链接 题意: 一张网格图,有障碍物,每秒能向上下左右四个方向走1~k步,问从起点到终点的最短时间是多少,不能到达则输出-1. 分析:裸的BFS,但不剪枝会T。 剪枝1: 扩展时就判断是否到达终点 936ms/2000ms 物美价廉的剪枝 #include<bits/stdc++.h> using namespace std; const int N=10...原创 2019-09-29 16:08:16 · 125 阅读 · 1 评论 -
洛谷P1126 机器人搬重物 (BFS)
超多细节,值得重写很多遍。 #include<bits/stdc++.h> using namespace std; int X[]={-1,0,1,0},Y[]={0,1,0,-1}; int n,m,a[60][60]; bool vis[60][60][4];//访问标记(坐标+方向) struct node{ int x,y,f,step; }; bool check(...原创 2019-08-11 20:04:13 · 152 阅读 · 0 评论 -
A strange lift HDU - 1548(Dijkstra/SPFA/BFS/DFS)
法一:Dijkstra+邻接表 对于每一层,在它与它up和down可到的两个楼层间建边(down的楼层要大于0),权值为1,求最短路。(代码中注释的地方是默写模板时出错的地方,要特别注意) #include<bits/stdc++.h> using namespace std; typedef pair<int,int> PII; const int N=205,M...原创 2019-08-06 15:17:49 · 130 阅读 · 0 评论 -
ACWing848 有向图的拓扑序列 基础算法
给定一个n个点m条边的有向图,图中可能存在重边和自环。 请输出任意一个该有向图的拓扑序列,如果拓扑序列不存在,则输出-1。 若一个由图中所有点构成的序列A满足:对于图中的每条边(x, y),x在A中都出现在y之前,则称A是该图的一个拓扑序列。 输入格式 第一行包含两个整数n和m 接下来m行,每行包含两个整数x和y,表示点x和点y之间存在一条有向边(x, y)。 输出格式 共一行,如...原创 2019-08-01 20:40:34 · 117 阅读 · 0 评论 -
PTA A1020 Tree Traversals
#include<bits/stdc++.h> using namespace std; const int maxn=45; int in[maxn],post[maxn],Hash[maxn],n;//题目数据范围N<=30, Hash数组不能设成35!!! struct node{ int val; node* left; node* right; node(i...原创 2019-03-16 09:59:13 · 139 阅读 · 0 评论 -
Dungeon Master POJ - 2251 BFS求最短路 三维BFS
题目链接 PS:POJ玄学CE(我猜是不支持初始化列表?懒得改了),UVA上过了。 #include<iostream> #include<queue> #include<cstring> using namespace std; struct node{ int l,x,y,step; }Node,t; int l,r,c,ans; int dr[]...原创 2019-02-07 16:22:26 · 100 阅读 · 0 评论 -
Oil Deposits HDU - 1241 BFS
#include<bits/stdc++.h> using namespace std; char a[105][105]; bool inq[105][105]; int ans,n,m; int dr[][2]={{-1,-1},{-1,0},{-1,1}, {0,-1},{0,1}, {1,-1},{1,0},{1,1}}; struct node{ int x...原创 2019-02-06 04:16:35 · 108 阅读 · 0 评论 -
魔板 BFS
#include<iostream> #include<queue> #include<string> #include<set> #include<cstdio> using namespace std; struct node{ string s,step; int dis; }; queue<node>q; set...原创 2019-02-06 03:34:18 · 140 阅读 · 0 评论 -
洛谷普及练习场-广度优先搜索
P1162 填涂颜色 #include<bits/stdc++.h> using namespace std; int mp[35][35]; bool inq[35][35]; int n; pair<int,int>Node(0,0); int dr[8][2]= { {-1,0},{0,-1},{0,1},{1,0} }; void BFS(){ ...原创 2019-02-14 15:56:35 · 284 阅读 · 0 评论