上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 17 下一页
摘要: //最优比例生成树:使用迭代法求解#include <stdio.h>#include <string.h>#include <math.h>#define vilnum 1001typedef struct node{int x;int y;int z;}node;//定义村落的位置和海拔const double eps = 0.0005;//定义精度,是最后... 阅读全文
posted @ 2010-05-04 13:32 北海小龙 阅读(317) 评论(0) 推荐(0) 编辑
摘要: //广度优先搜索#include <iostream>#include <string>using namespace std;#define mapsize 10#define quesize 1100int dir[6][3]={{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,-1},{0,0,1}};//定义6个方向char map[ma... 阅读全文
posted @ 2010-05-04 13:31 北海小龙 阅读(205) 评论(0) 推荐(0) 编辑
摘要: //解题思路:朴素的Prim算法#include <stdio.h>#include <string.h>//引入memset的头文件#define arraysize 51int maxData = 0x7fffffff;//定义最大值int dis[arraysize][arraysize];//定义邻接矩阵bool final[arraysize];//标识该点是否在... 阅读全文
posted @ 2010-05-04 13:31 北海小龙 阅读(191) 评论(0) 推荐(0) 编辑
摘要: //此题应该从后往前搜索,因为营救者不止一个,第一个找到的营救者时间最短,搜索过程要采用优先队列#include <iostream>#include <queue>using namespace std;//优先队列默认的是从大到小,此处必须重置为从小到大typedef struct b{ int x, y, step; bool operator < (const... 阅读全文
posted @ 2010-05-04 13:30 北海小龙 阅读(363) 评论(0) 推荐(0) 编辑
摘要: //题目大意:求相连的块数//解题思路:使用广度优先搜索,搜索的次数即相连的块数#include <iostream>using namespace std;#define arraysize 101int dir[8][2] = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};//定义搜索的8个方向typedef str... 阅读全文
posted @ 2010-05-04 13:30 北海小龙 阅读(215) 评论(0) 推荐(0) 编辑
摘要: //此题应该从后往前搜,因为营救者不止一人#include<stdio.h>#include<string.h>int d[4][2]={{1,0},{-1,0},{0,-1},{0,1}};//设置搜索的4个方向int m,n,si,sj,sti,stj,flag;int min;char map[202][202];int len[202][202];void dfs(... 阅读全文
posted @ 2010-05-04 13:29 北海小龙 阅读(321) 评论(0) 推荐(0) 编辑
摘要: //简单的广度优先搜索//解题思路:剪枝//*思路首先分析可走的路的总数是否大于等于最短路径数(最短路径数=a+b+c-2),如果小于怎样都无法到达出口//*所以可以直接输出-1,还有总的时间数小于最短时间(最短时间数=a+b+c-2)也是无法到达出口,除去以上情况//*然后使用BFS进行搜寻就可以了#include <stdio.h>#include <queue>usi... 阅读全文
posted @ 2010-05-04 13:28 北海小龙 阅读(214) 评论(0) 推荐(0) 编辑
摘要: //迷宫求解的变形:广度优先搜索//关键解决重复回路问题#include <iostream>using namespace std;int n,m;int map[10][10];int mark[10][10];//该地的剩余时间int sj,sk,ej,ek;int dir[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};//遍历的四个方向int mint... 阅读全文
posted @ 2010-05-04 13:28 北海小龙 阅读(296) 评论(0) 推荐(0) 编辑
摘要: //朴素的广度优先搜索#include <iostream>#include <string>using namespace std;#define arraysize 10typedef struct node{int col;int row;int step;//记录该点到原点的距离}node;node myqueue[100];bool hash[arraysize]... 阅读全文
posted @ 2010-05-04 13:27 北海小龙 阅读(160) 评论(0) 推荐(0) 编辑
摘要: //朴素的广度优先搜索,可以作为模板#include <iostream>using namespace std;#define arraysize 21char map[arraysize][arraysize];//记录该迷宫的结构图int si,sj;typedef struct node{int x;int y;}node;node myqueue[arraysize*arra... 阅读全文
posted @ 2010-05-04 13:27 北海小龙 阅读(145) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 17 下一页