
搜索问题
文章平均质量分 77
jordandandan
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
同余模定理解决大数问题(poj1426)
解题方法: BFS+同余模定理 首先我们简单回顾一下 朴素搜索 法: n=6 1%6=1 (k=1) { (1*10+0)%6=4 (k=10) { (10*10+0)%6=4 (k=100) { (100*10+0)%6=4 (k=1000) (100*转载 2013-07-26 17:37:32 · 1065 阅读 · 0 评论 -
bfs+dfs(poj3083)
解题思路: 定义四个方向 :上下左右以此为0123 靠左走优先和靠右左优先用dfs 最短路用bfs 注:不能以循环次数为迭代深度,这里应该是上次深度+1 #include #include using namespace std; typedef struct S { int r,c; int depth; }SE; SE s,e; //起止点 int Lstep;原创 2013-07-26 22:04:50 · 751 阅读 · 0 评论 -
poj3126 bfs
水题 解题思路: 按位枚举,40入口bfs,对于偶数剪枝,利用根号法判定素数,即n若能被[2,根号n]的数整出即不是素数 源码: #include #include #include using namespace std; int a,b; typedef struct pr { int prime; int depth; } num; bool visit[1原创 2013-07-27 12:00:30 · 646 阅读 · 0 评论 -
poj3009
很有意思的题,注意当碰撞完石头后,回溯要恢复石头,否则下一次再深搜时就WA了 。 要注意题目中说明大于10步就impossible,我们在深搜时应该以此#include #include using namespace std; typedef struct S { int r,c; bool status;//true运动false静止 }SE; SE s,e; int w原创 2013-07-27 15:32:12 · 621 阅读 · 0 评论 -
poj 2631(dfs求最长路径)
题目中要求有1w个点,所以我们用邻接表来建立图而不要用邻接矩阵 用degree来计算节点的度,选出一个叶子结点从他dfs一次最长路径,找到这个最长路径的结束点s,再从s来dfs求得最长路径 源码: #include #include #include using namespace std; int mx,mxp; int degree[100005]; bool visit[1000原创 2013-08-14 15:14:19 · 3082 阅读 · 0 评论