摘要: 题目的本意应该是叫你求出最小生成树的最大边,和边的个数,最后把每条边的连接情况打印出来。View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<math.h> 5 #define N 15001 6 7 int father[1001];//按照模板敲的 8 int p[N], n, m; 9 typedef struct 10 {11 int x, y;12 int w; 13 }edge;14 edge e[N];15 16 int 阅读全文
posted @ 2012-04-19 23:29 zhongya 阅读(175) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 5 int cmp(const void *a,const void *b)//这里要用double貌似用int不行 6 { 7 return *(double *)a > *(double *)b ? 1 : -1; 8 } 9 10 int main()11 {12 int i, n, ncases;13 double total; 14 double weight[101];15 16 while( .. 阅读全文
posted @ 2012-04-19 23:22 zhongya 阅读(293) 评论(0) 推荐(1) 编辑
摘要: 此算法在POJ上跑超时了,用了3s+;具体的思路和Prim算法一样View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 755 5 6 int rank[N],father[N]; 7 int dis_sum, x[N], y[N]; 8 typedef struct 9 {10 int x, y;11 int w; 12 }edge;13 edge e[N*N];14 15 int cmp(const void *a,const void *b 阅读全文
posted @ 2012-04-19 18:51 zhongya 阅读(251) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define N 760 5 #define Maxint 99999999 6 7 double lowcost[N], c[N][N]; 8 double x[N], y[N]; 9 int towns, m, s[N], closest[N],path[N][N];10 11 double distance(int i,int j)//用double为了防止int数据存不下12 {13 return (x 阅读全文
posted @ 2012-04-19 17:07 zhongya 阅读(173) 评论(0) 推荐(0) 编辑