最小生成树
文章平均质量分 62
lightblueme
Hello Programmers!
展开
-
poj 2485 highway lightblueme
#include #include #include #include using namespace std; #define NUM 505 int father[NUM]; void initroot(){ for(int i=0;i<505;i++) father[i]=-1; } int findroot(int n){ int x=n;原创 2013-01-22 17:16:46 · 215 阅读 · 0 评论 -
POJ 1258 lightblueme Agri Net angry!89次的失误终于得到最后的成功
低级错误,困扰了我整整两天!kruskal方法用于求最小生成树,对于属于不同set的节点进行合并时需要找到相应的set的根节点root1和root2,将root1的父节点指针指向root2或者相反。切莫只是改变当前节点的指针。就是这个低级的错误是我同提交了89次才终于成功!89次!! #include #include #define NUM 105 typedef struct原创 2013-01-26 22:41:52 · 295 阅读 · 0 评论 -
poj 1258 prim lightblueme
对于标准的矩阵输入使用矩阵作为存储结构可以简化算法的设计。 #include #include #include using namespace std; #define NUM 105 int costmatrix[NUM][NUM]; int flag[NUM]; void init(){ for(int index=0;index<NUM;index++){ flag[i原创 2013-01-29 13:31:05 · 362 阅读 · 0 评论 -
poj 2075 lightblueme double qsort cmp函数的写法
对于int类型的数据使用qsort可以为: int a,b; int cmp(){ return a-b; } 而对于double类型 int a,b; if(a>b) return 1; if(a==b) return 0; else return -1; poj 2075 code #include #include #include #原创 2013-01-30 21:23:15 · 385 阅读 · 0 评论 -
poj 2349 最小生成树 careful everything!
#include #include #include #include using namespace std; #define NUM 505 typedef struct{ int x,y; }Node; Node nodes[NUM]; typedef struct{ int from; int to; double cost; }Edge; int cmp(con原创 2013-01-31 21:16:30 · 428 阅读 · 0 评论