
BFS
广度优先搜索
moyangxian
MoYang
展开
-
HDU - 1240 Asteroids!(三维BFS)
题目链接题意:一个nnn的三维空间,给出起点坐标和终点坐标,求最小步数。题记:简单BFS,需要注意的是我们建图的坐标和输入的坐标是不一样的,需要处理一下。#include<bits/stdc++.h>using namespace std;const int N=15;char a[N][N][N];int dis[6][3]={{0,0,1},{0,1,0},{1,0,0},{0,0,-1},{0,-1,0},{-1,0,0}};int x1,y1,z1,x2,y2,z2,n原创 2020-05-14 13:36:24 · 135 阅读 · 0 评论 -
POJ - 3414 Pots(BFS)
题目链接题意:两个盆,一个最多能装a体积水,另一个能装b体积水。有三种操作:1、把其中一盆水装满2、把其中一盆水倒掉3、把其中一盆水倒入另外一盆水中,如果超过了当前盆的容量,则只倒到盆的最大容量。三种操作分为6种状态,a加满,b加满,b倒入a,a倒入b,a倒掉,b倒掉。bfs遍历。在结构体中吧两盆水的体积,操作次数和操作状态记录下来,vis数组记录已经用过的状态。#include<iostream>#include<queue>#include<string&原创 2020-05-12 14:32:07 · 99 阅读 · 0 评论 -
POJ1426-Find The Multiple(BFS+同余)
题目链接题意:找出一个n的倍数,这个数只含1和0。参考博客题记:可以用BFS的思想去做,每位数只有1和0两种情况(第一位必须是1)。那么我们BFS时是类似于一个二叉树的形状(最好画图理解)同余定理:(a*b)%n = (a%n *b%n)%n(a+b)%n = (a%n +b%n)%n具体证明可以看上面的参考博客。下图可做参考(字有些难看 )。图中n取6,黑体字为当前数字,红体字为当前数字余6的余数,蓝体字是当前数字的序号(BFS的顺序)。可以看出是和二叉树是一样的,所以可以用二叉树的性质原创 2020-05-11 23:29:37 · 160 阅读 · 0 评论 -
Catch That Cow(BFS)
题目链接题记:简单BFS#include<iostream>#include<queue>#include<cstring>using namespace std;const int N=1e5+1;typedef long long ll;int n,k;int vis[N];struct node{ int x,step;};...原创 2020-04-29 17:03:40 · 96 阅读 · 0 评论 -
洛谷 P1332 血色先锋队(BFS)
题目链接题记:简单BFS。#include<iostream>#include<cstring>#include<queue>using namespace std;const int N=510,M=1e5+10;int n,m,a,b;int vis[N][N];int s[M][3];int maps[N][N];int dis[]...原创 2020-04-22 22:11:04 · 396 阅读 · 0 评论 -
洛谷 P2298 Mzc和男家丁的游戏(BFS)
题目链接题记:简单BFS。#include<iostream>#include<queue>#include<cstring>using namespace std;const int N=2005;char m[N][N];int dis[][2]={1,0,0,1,-1,0,0,-1};int x1,y1,x2,y2,n,n1;struc...原创 2020-04-22 21:27:32 · 270 阅读 · 0 评论 -
洛谷 P1746 离开中山路(BFS)
题目链接题记:简单BFS。#include<iostream>#include<queue>#include<cstring>using namespace std;const int N=1005;char m[N][N];int dis[][2]={1,0,0,1,-1,0,0,-1};int x1,y1,x2,y2,n;struct n...原创 2020-04-22 21:18:32 · 838 阅读 · 0 评论 -
洛谷 P1747 好奇怪的游戏(BFS)
题目链接题记:简单BFS。#include<iostream>#include<queue>#include<cstring>using namespace std;const int N=25;int m[N][N];int room[N][N];int dis[][2]={-2,-2,-2,2,2,-2,2,2,-2,1,-2,-1,2,1...原创 2020-04-22 21:02:38 · 197 阅读 · 0 评论 -
POJ 1562 Oil Deposits(BFS)
题记:简单bfs。#include<iostream>#include<queue>#include<cstring>using namespace std;const int N=105;typedef pair<int,int>PII;int n,m;char a[N][N];int room[N][N];int dis[]...原创 2020-04-12 21:13:43 · 175 阅读 · 0 评论 -
HDU 1548A strange lift
题记:简单bfs题目。#include<iostream>#include<queue>using namespace std;const int N=210;int a,b,n;struct Lift{ int w; int x; int num;}lift[N];bool check(int w){ if(w<1...原创 2020-04-11 20:48:29 · 121 阅读 · 0 评论 -
走迷宫(BFS)
题目链接给定一个n*m的二维整数数组,用来表示一个迷宫,数组中只包含0或1,其中0表示可以走的路,1表示不可通过的墙壁。最初,有一个人位于左上角(1, 1)处,已知该人每次可以向上、下、左、右任意一个方向移动一个位置。请问,该人从左上角移动至右下角(n, m)处,至少需要移动多少次。数据保证(1, 1)处和(n, m)处的数字为0,且一定至少存在一条通路。输入格式第一行包含两个整数n和...原创 2020-04-07 20:18:54 · 172 阅读 · 0 评论 -
洛谷 P1443 马的遍历
题目链接:https://www.luogu.com.cn/problem/P1443题记:注意最后输出的格式…#include<bits/stdc++.h>using namespace std;int dir[8][2]={{-2,1},{2,1},{1,2},{1,-2},{2,-1},{-1,-2},{-2,-1},{-1,2}};int a[405][405];...原创 2020-02-24 15:15:49 · 154 阅读 · 0 评论 -
洛谷 P1162 填涂颜色
题目链接:https://www.luogu.com.cn/record/31010382#include<bits/stdc++.h>using namespace std;int dir[4][2]={{-1,0},{0,-1},{1,0},{0,1}};int a[35][35];struct node{int x,y;};int n;void bfs(int d...原创 2020-02-24 15:14:18 · 139 阅读 · 0 评论