摘要: 1 /*简单BFS 2 Author:sorry 3 Date:2012/9/27 21:20 4 以起始点开始,下一步有六种可能,north,south,west,east,up,down 5 逐一列举并入队(如果合法的话),直到终点为止,若直到队列为空也 6 不能出去的话,那就是Trapped!了 7 剪枝:以入过队列的就不需重新入队了 8 */ 9 #include<iostream> 10 #include<stdio.h> 11 #include<queue> 12 #include<string.h> 13 using namespa 阅读全文
posted @ 2012-09-27 21:23 sorryhao 阅读(201) 评论(0) 推荐(0)
摘要: 简单BFS思路很简单,就是从起点始,有八个选择可走(如果每个都合法的话)一直到终点为止,我做麻烦了,其实可以用二维数组来表示下一步要走的方向用G++须加头文件#include <stdio.h>#include<string.h> 1 #include <stdio.h> 2 #include<string.h> 3 #include <queue> 4 #include<iostream> 5 #include<queue> 6 using namespace std; 7 #define maxn 301 阅读全文
posted @ 2012-09-27 11:41 sorryhao 阅读(178) 评论(0) 推荐(0)
摘要: 1 /* BFS入门题 2 思路:以n为始点开始搜索,直到搜到k为止 3 注意需剪枝,否则会超时,剪枝最重要的一点就是: 4 已经入队过得点不许再重复入队 5 */ 6 #include<iostream> 7 #include<queue> 8 using namespace std; 9 bool flag[200005];10 struct node11 {12 int x,t;13 };14 void BFS(int n,int k)15 {16 queue<node> q;17 node a;18 memset(flag,false,sizeof( 阅读全文
posted @ 2012-09-27 11:33 sorryhao 阅读(141) 评论(0) 推荐(0)