hdu 1102(prime 算法)
2011-07-29 19:32
330 查看
#include <iostream> #include<cstdio> #include <queue> #include<string.h> using namespace std; const int MAX=99999; int mat[105][105]; int N,lowcost[105],road; void prime() { for(int i=2;i<=N;i++) lowcost[i]=mat[1][i]; for(int i=2;i<=N;i++) { int temp=lowcost[i],k=i; for(int j=2;j<=N;j++) if(temp>lowcost[j]) { temp=lowcost[j]; k=j; } road+=temp; lowcost[k]=MAX; for(int j=2;j<=N;j++) if(mat[k][j]<lowcost[j]&&lowcost[j]<MAX) lowcost[j]=mat[k][j]; } } void makeSet(int n) { for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>mat[i][j]; } int main() { int Q,m,n; while(cin>>N) { road=0; makeSet(N); cin>>Q; while(Q--) { cin>>m>>n; mat[m] =mat [m]=0; } prime(); cout<<road<<endl; } }
相关文章推荐
- hdu 1102 prime算法
- hdu 1102 Constructing Roads(Prime算法)
- hdu 1162Eddy's picture Prime算法求最小生成树
- hdu 1102 prime Constructing Roads
- hdu 1102 Constructing Roads<java><prime>
- poj1258 Agri-Net +hdu 1233 还是畅通工程 (最小生成树Prime算法)
- hdu 1233(还是畅通工程)(prime算法,克鲁斯卡尔算法)(并查集,最小生成树)
- HDU 2138 How many prime numbers(米勒拉宾素数测试算法)
- HDU 1102 prime
- hdu-1102 Constructing Roads(prime)
- HDU 1102 Constructing Roads -- prime
- HDU 1162 Eddy's picture (prime算法_裸题)
- prime 算法 hdu 1875
- hdu1102 prime()和kruskal()两种方法,感觉不错。 如果你要问我:我只能说,实力决定一切
- prime 算法 hdu 1879
- hdu 1879 最小生成树【prime算法】
- HDU--1233 -- 还是畅通工程 [kruskal算法] [prime算法] [并查集]
- hdu1102(prime)
- hdu_1102_prime
- Prim 算法, hdu 1102 Constructing Roads