![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
bfs
文章平均质量分 62
goto_1600
我何来寂寞,哪有寂寞可言。
展开
-
leetcode 6054. 逃离火灾 思维 bfs
link 思路: 当然可以二分 + bfs 复杂度O(log(n∗m)n∗m)O(log(n*m)n*m)O(log(n∗m)n∗m) 这个比较好想,但如何进一步优化,我们可以逆向考虑,从终点倒着找到离终点最近的火和最近的人的距离,当然如果火比人先到那肯定就是-1,如果找不到火就是1e9,然后就判断最近的火和人的位置关系,因为右下角只有两种转移位置,一种是上方一种是左方,有个比较有意思的性质,到两个方向的人的差要么是0,要么是1,而火的差距可以取到0,1,2,大家可以思考一下为什么? 如果最近的火到这两个原创 2022-05-02 13:37:27 · 255 阅读 · 0 评论 -
D. The Strongest Build二叉堆,map乱搞
Link 题意: 给定n个序列,要从每个序列选出一个数,价值为选出来的总和,然后有m个限制,代表m个序列不能用,求最大值 n<=10∑ ci<=2e5 m<=2e5n<=10 \sum~ci<=2e5~m<=2e5n<=10∑ ci<=2e5 m<=2e5 思路: 一开始想着类似于n路尺取,也就是先把所有最大值放进堆里,然后每次尺取花费最小的,然后会发现会漏掉某些情况。正解是暴力bfs,因为m<=2e5也就是原创 2021-09-21 20:36:15 · 368 阅读 · 0 评论 -
Spicy Restaurant (暴力多源bfs)
Link 题意: 有n个城市,每个城市有个辣度,给你个图,有q次询问求某个点开始,忍耐度为w,求最近辣度<=w的最短路,边权为1。 q<=5e5 n<=1e5 m<=1e5 wi,w<=100q<=5e5 \space n<=1e5 \space\space \space m<=1e5 \space wi,w<=100q<=5e5 n<=1e5 &nb原创 2021-09-14 08:57:27 · 516 阅读 · 1 评论 -
Fire 多起点bfs
Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the maze neglected to create a fire escape plan. Help Joe escape the maze. Given Joe’s location in the ma...原创 2020-03-24 10:02:23 · 212 阅读 · 0 评论 -
枚举+bfs
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...原创 2020-03-23 23:34:09 · 756 阅读 · 0 评论 -
双起点bfs
Pass a year learning in Hangzhou, yifenfei arrival hometown Ningbo at finally. Leave Ningbo one year, yifenfei have many people to meet. Especially a good friend Merceki. Yifenfei’s home is at the co...原创 2020-03-23 23:29:14 · 266 阅读 · 0 评论 -
非常可乐bfs搜索
大家一定觉的运动以后喝可乐是一件很惬意的事情,但是seeyou却不这么认为。因为每次当seeyou买了可乐以后,阿牛就要求和seeyou一起分享这一瓶可乐,而且一定要喝的和seeyou一样多。但seeyou的手中只有两个杯子,它们的容量分别是N 毫升和M 毫升 可乐的体积为S (S<101)毫升 (正好装满一瓶) ,它们三个之间可以相互倒可乐 (都是没有刻度的,且 S==N+M,101>S...原创 2020-03-23 23:21:48 · 242 阅读 · 0 评论 -
最短路练习之最优乘车
H城是一个旅游胜地,每年都有成千上万的人前来观光。 为方便游客,巴士公司在各个旅游景点及宾馆,饭店等地都设置了巴士站并开通了一些单程巴士线路。 每条单程巴士线路从某个巴士站出发,依次途经若干个巴士站,最终到达终点巴士站。 一名旅客最近到H城旅游,他很想去S公园游玩,但如果从他所在的饭店没有一路巴士可以直接到达S公园,则他可能要先乘某一路巴士坐几站,再下来换乘同一站台的另一路巴士, 这样换乘几次后到...原创 2020-03-20 23:03:13 · 384 阅读 · 0 评论 -
bfs floodfill 算法
1 2 3 4 5 6 7 ############################# 1 # | # | # | | # #####—#####—#---#####—# 2 # # | # # # # # #—#####—#####—#####—# 3 # | | # # # # #...原创 2020-03-13 23:18:52 · 273 阅读 · 0 评论 -
树与图的广度优先遍历(bfs)
题目点这里 #include<iostream> #include<string.h> #include<queue> using namespace std; const int N=100010; int h[N],e[N],idx,ne[N]; int d[N]; int n,m; bool st[N]; int bfs() { memset(...原创 2020-02-12 14:17:48 · 326 阅读 · 0 评论 -
bfs写法 nightmare
1代表空地 0代表阻挡物 3代表出口 4代表补给站 问最短路径 因为可以重复走 为了防止超时 要用一个use数组 要是当前的时间比use数组的大 更新use数组的值 相当于剪枝 AC代码: #include<stdio.h> #include<queue> #include<string.h> using namespace std; struct node{ ...原创 2020-01-31 12:52:00 · 479 阅读 · 0 评论 -
bfs pot
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) from the tap; DROP(i) empty the pot ...原创 2020-01-26 13:33:56 · 214 阅读 · 0 评论 -
bfs
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...原创 2020-01-24 21:25:51 · 188 阅读 · 0 评论 -
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 ≤ 10...原创 2020-01-23 22:50:45 · 184 阅读 · 0 评论 -
迷宫问题 输出路径
定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线。 Input 一个5 × 5的二维数组,表示一个迷...原创 2020-01-19 21:44:51 · 354 阅读 · 0 评论