搜索专题
dfs 和 bfs
YikNjy
难留少年时,总有少年来。
展开
-
The 2022 ICPC Asia Regionals Online Contest (I)
The 2022 ICPC Asia Regionals Online Contest (I)H Step Debugging原创 2022-09-19 16:57:22 · 534 阅读 · 2 评论 -
poj bfs3278
#include<iostream>#include<algorithm>#include<cstring>#include<queue>using namespace std;int n,k;int x;int d[100010],ff[100010];int bfs(){ queue<int>q; q.push(n); d[n]=0; ff[n]=1; while(!q.empty())原创 2021-04-25 18:36:38 · 75 阅读 · 0 评论 -
poj 2251 bfs
Time47msMemory356kB#include<iostream>#include<algorithm>#include<cstring>#include<queue>using namespace std;char s[30][30][30];int d[30][30][30];int a,b,c,t;int sx,ex,sy,ey,sz,ez;int dx[]= {0,0,0,0,1,-1},dy[]= {0,0,1,-原创 2021-04-24 21:32:21 · 47 阅读 · 0 评论 -
poj1321 dfs(bool数组memset更快(比int),15ms左右)
//Time//47ms//Memory//184kB#include<iostream>#include<algorithm>#include<cstring>using namespace std;char s[10][10];int ss[10];int n,k,num;void dfs(int l,int step){ if(step==k) { num++; return; }原创 2021-04-24 20:13:01 · 164 阅读 · 0 评论 -
杭电1455 dfs 剪枝
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue> #include<stack> #inclu原创 2021-04-24 17:15:21 · 60 阅读 · 0 评论 -
杭电2102 a计划
可怜的公主在一次次被魔王掳走一次次被骑士们救回来之后,而今,不幸的她再一次面临生命的考验。魔王已经发出消息说将在T时刻吃掉公主,因为他听信谣言说吃公主的肉也能长生不老。年迈的国王正是心急如焚,告招天下勇士来拯救公主。不过公主早已习以为常,她深信智勇的骑士LJ肯定能将她救出。现据密探所报,公主被关在一个两层的迷宫里,迷宫的入口是S(0,0,0),公主的位置用P表示,时空传输机用#表示,墙用表示,平地用.表示。骑士们一进入时空传输机就会被转到另一层的相对位置,但如果被转到的位置是墙的话,那骑士们就会被撞死。骑原创 2021-04-23 20:35:06 · 105 阅读 · 0 评论 -
dfs笔记之素环问题
素环问题一个环由n个圆组成,如图所示。将自然数1,2,…,n分别放入每个圆中,相邻两个圆中的数之和应为素数。注:第一圈的数字应始终为1。输入n(0<n<20)。输出输出格式如下所示。每一行都表示环中从1顺时针和逆时针开始的一系列圈数。数字的顺序必须满足上述要求。按词典顺序打印解决方案。你要写一个程序来完成上述过程。在每个案例后打印一个空行。样本输入68样本输出案例1:1 4 3 2 5 61 6 5 2 3 4案例2:1 2 3 8 5 6 7 41 2 5原创 2021-04-19 20:43:11 · 400 阅读 · 0 评论 -
c++笔记dfs
num++在函数调用的时候并不等于num+1ex:dfs(x,y,num++)和dfs(x,y,num+1)穿参的时候一个num变了,一个没有变。原创 2021-04-05 20:21:04 · 83 阅读 · 0 评论 -
dfs之奇偶剪枝
杭电1010dfs杭电1010这道经典的dfs剪枝例题引出奇偶剪枝:先看ac码:#include<iostream>#include<algorithm>#include<string.h>#include<math.h>using namespace std;int a,b,c,x,y,zx,zy;char s[10][10];int zb[]= {-1,1,0,0},yb[]= {0,0,1,-1};int flag=0;void原创 2021-04-05 20:16:20 · 74 阅读 · 0 评论