随笔分类 -  最小生成树

poj 3026
摘要:算法:1.刚开始自己的算法是一次BFS,求出各点距离,建好图,但是提交上去一直WA,不解。2.修正算法枚举所有A与S点,AC。。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<queue>#include<iostream>using namespace std;struct node{ int a, b, num; bool operator < ( const node& 阅读全文

posted @ 2012-07-12 14:04 more think, more gains 阅读(159) 评论(0) 推荐(0)

poj 1258
摘要:原来POJ上也有这么多水题,连续三道裸的最小生成树了。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];int N, e, set[2100], mp[510][510 阅读全文

posted @ 2012-07-12 10:09 more think, more gains 阅读(171) 评论(0) 推荐(0)

poj 2485 最小生成树
摘要:算法:又是裸得最小生成树。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];int N, e, set[2100], mp[510][510];int find( in 阅读全文

posted @ 2012-07-12 10:02 more think, more gains 阅读(160) 评论(0) 推荐(0)

poj 1789 最小生成树
摘要:1A,在POJ上好久没有1A了。。算法:裸的最小生成树,关键时认真读懂题意。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int a, b, num; bool operator < ( const node& A) const { return num < A.num; }}edge[4100000];char truck[2100][10]; 阅读全文

posted @ 2012-07-12 09:33 more think, more gains 阅读(152) 评论(0) 推荐(0)

并查集最小生成树复习
摘要:HDU 1856 more is better 简单并查集View Code #include <stdio.h>int set[100010], num[100010];int maxn = 1;int find( int x){ // return x == set[x] ? x : set[x] = find(set[x]); if( x != set[x] ) { set[x] = find(set[x]); } return set[x];}void merge( int x, int y){ int x1 = find( x ); int y1 = find( ... 阅读全文

posted @ 2012-03-11 11:17 more think, more gains 阅读(194) 评论(0) 推荐(0)

hdu 1233
摘要:#include<stdio.h>#include<algorithm>using namespace std;int father[110],N,M;struct node{ int i,j,v;}T[5000];int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==father[x]?x:father[x]=find(father[x]);}void merge(int x,int y){ x=find(x); y=find(y); if(x!=y) father[x]=y;}in 阅读全文

posted @ 2011-04-30 11:13 more think, more gains 阅读(174) 评论(0) 推荐(0)

畅通工程
摘要:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>using namespace std;struct node{ int i; int j; int v;}T[5000];int father[110],rank[110];int N,M,t;int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==father[x]?x:father[x]=find(father[x] 阅读全文

posted @ 2011-04-30 10:32 more think, more gains 阅读(153) 评论(0) 推荐(0)

继续畅通工程
摘要:#include<stdio.h>#include<stdlib.h>#include<algorithm>using namespace std;struct node{ int i,j,v,u;}T[10100];int father[10100],N,M;int cmp(node a,node b){ return a.v<b.v;}int find(int x){ return x==fa... 阅读全文

posted @ 2011-04-30 09:34 more think, more gains 阅读(162) 评论(0) 推荐(0)

导航