随笔分类 - 搜索
搜索理论
摘要:宽度优先搜索bfs一、搜索的bfs,宽度优先搜索,一般用于求最短的得到到目的地的距离,有个起始点,先把这个起始点入队列,不要忘记将这个起始点标记为已经利用,不然会走回来的,然后是与这个起始点的周围的点的监测,若可以行的通,我们一一检测这些扩展出来的点,若是目的地就结束了,若不是目的地,将改点标记为已经利用,并将该点入队列。二、搜索的双向bfs,双向的bfs一般来说可以用单向解决,但是单向的效率上还是差了点,适合双向bfs的题目有一些共同特点:给出起始和最终状态,让求出一条从初始到末状态的最短路。双向bfs的实现过程: 从初始结点开始扩展,每扩展一层,在从目标节点按照产生系统相反的办法来扩展结点
阅读全文
Tempter of the Bone(诱惑的骨头)
摘要:hdoj 1010题目大意:给一个地图,在规定时间内刚好找到出口,不早也不能晚解决:dfs+剪枝#include <iostream>#include <cstdio>#include <cmath>using namespace std;#define s scanf#define p printf#define d "%d"char map[8][8];int n,m,step;bool escape;int sx,sy,ex,ey;int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};void dfs(in
阅读全文
maze(迷宫)
摘要:poj 3984题目大意:解决:bfs,关键是对路径的保存#include <iostream>#include <cstring>#include <vector>#include <queue>using namespace std;int map[5][5];struct node{ int x,y;};//此处定义了一个存放上一个坐标的路径结构体,采用递归输出node path[5][5];queue<node> q;int sx=1,sy=1;int dx[]={1,-1,0,0};int dy[]={0,0,1,-1};i
阅读全文
Sum It Up(加和)
摘要:zoj1711题目大意:给出一个和,求出所给数相加等于这个和的所有不同情况解决:The numbers in each list appear in nonincreasing order, and there may be repetitions.有序是前提,由于有4 6 4 3 2 2 1 1这样的数据存在,我们必须判断重复的等式6=3+2+1(第一个1)或者是6=3+2+1(第二个1)如何判断呢见代码//#include <iostream>#include <cstdio>#include <cstring>using namespace std;i
阅读全文
Additive equations(和式)
摘要:zoj 1204题目大意:给出一些数字,求出某几个数字之和等于给出的某一个数字 ,并按照要求输出解决: 排序,dfs#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int num[35];bool flag;int res[35],n;void dfs(int start,int dest_deep,int current_deep,int current_sum){ if(current_deep==des
阅读全文
浙公网安备 33010602011771号