随笔分类 -  最小生成树&并查集

【解题报告】【HDOJ1233】【最小生成树】还是畅通工程
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1233prim最小生成树 1 #include<stdio.h> 2 #include<string.h> 3 #define INF 0x3f3f3f3f 4 #define min(a,b) (a>b?b:a) 5 6 long int map[101][101]; 7 long int n,m; 8 int set[101]; 9 long int sum;10 void prim_init()11 {12 int i,a,b,c;13 memset(map,INF,siz 阅读全文

posted @ 2012-07-21 18:32 coding封神 阅读(120) 评论(0) 推荐(0)

【解题报告】【HDOJ1102】【最小生成树】Constructing Roads
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1102prim最小生成树 1 #include<stdio.h> 2 #include<String.h> 3 #define INF 0x3f3f3f3f 4 int map[105][105]; 5 int set[105]; 6 int sum; 7 int n; 8 void prim(){ 9 int t=INF,tt,i,j;10 for(i=1;i<=n;i++){11 if(set[i])12 for(j=1;j<=n;j++... 阅读全文

posted @ 2012-07-21 18:30 coding封神 阅读(145) 评论(0) 推荐(0)

【解题报告】【HDOJ1272】【并查集】小希的迷宫
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1272判断条件1.无环2.连通(其实就是构造树的条件)注意:要考虑树时空的情况,0 0也是树,空树。 1 #include<stdio.h> 2 #include<string.h> 3 int root[100001]; 4 int used[100001]; 5 int find(int x) 6 { 7 int t; 8 if(root[x]==x) 9 return x;10 t=find(root[x]);11 root[x]=t;12 ... 阅读全文

posted @ 2012-07-21 16:49 coding封神 阅读(136) 评论(0) 推荐(0)

【解题报告】【HDOJ1213】【并查集】How Many Tables
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 1 #include<stdio.h> 2 #include<string.h> 3 int father[1005]; 4 int record[1005]; 5 int find(int x) 6 { 7 int t; 8 if(father[x]==x) 9 return x;10 t=find(father[x]);11 father[x]=t;12 return t;13 }14 int main()15 {16 in... 阅读全文

posted @ 2012-07-21 16:45 coding封神 阅读(130) 评论(0) 推荐(0)

【解题报告】【HDOJ1232】【并查集】畅通工程
摘要:题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1232 1 #include<stdio.h> 2 #include<string.h> 3 int father[1005]; 4 int record[1005]; 5 int find(int x)//用来寻找根节点 6 { 7 int t; 8 if(father[x]==x) 9 return x;10 t=find(father[x]);11 father[x]=t;12 return t;13 }14 int main()15 {... 阅读全文

posted @ 2012-07-21 16:40 coding封神 阅读(125) 评论(0) 推荐(0)

导航