摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1875最小生成树,用Prim算法。源代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 const double INF=100000000.0; 8 int visit[110]; 9 double d[110],w[110][110];10 struct11 {12 int x,y;13 } re[110];14 15 int main()16 {17 int n,c... 阅读全文
posted @ 2013-08-09 21:20 小の泽 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=2122注意考虑只有一个城市的情况!!!还有题目有点问题,应该是接下来一共m行~~~赤果果的最小生成树,用Kruskal。源代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef struct{ 6 int from,to,c; 7 }road; 8 road r[10000010]; 9 int fa[1010];10 int count;11 12 int cmp(const void *a,const void... 阅读全文
posted @ 2013-08-09 15:31 小の泽 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=1102这题有多组测试数据,表示被坑了……最小生成树,用Kruskal~源代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef struct{ 6 int from,to,c; 7 }road; 8 road r[250010]; 9 int fa[510];10 int count;11 12 int cmp(const void *a,const void *b){13 return (((road *)a... 阅读全文
posted @ 2013-08-09 14:31 小の泽 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 题目:http://poj.org/problem?id=2485因为让你求最长边,所以首先想到的是Kruskal算法(他加入生成树的最后一条边是最大边),注意n个城市有n-1条边!!!源代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 typedef struct 6 { 7 int from,to,c; 8 } road; 9 road r[250010];10 int fa[510];11 int count;12 13 int cmp(const void *a,const void *b)14 {15... 阅读全文
posted @ 2013-08-09 13:35 小の泽 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 题目:http://acm.hdu.edu.cn/showproblem.php?pid=3371最小生成树,这题用Kruskal算法加并查集,对于已经连通的集合处理方式是把他们的根结点设为同一个。注意边的添加不能使最小生成树产生回路。还有只能用C++交,用G++会超时啊~~~orz源代码: 1 #include 2 #include 3 #include 4 using namespace std; 5 //const int INF=100000000; 6 const int maxn=255003; 7 int road,ans,i,j,n,m,k; 8 int from[maxn]. 阅读全文
posted @ 2013-08-09 11:33 小の泽 阅读(153) 评论(0) 推荐(0) 编辑