UVa 10397 Connect the Campus
来源:互联网 发布:zookeeper linux 下载 编辑:程序博客网 时间:2024/06/05 10:12
最小生成树
Kruskal
#include<cmath>#include<iostream>#include<cstdio>#include<algorithm>using namespace std;struct A{ int x,y; double z;}a[500010];int r[755];int find_(int x){ while(x!=r[x]) x=r[x]; return x;}int cmp(A a,A b){ return a.z<b.z;}int main(){ int n,m,i,j,k,c,b,x[755],y[755]; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]); for(i=1;i<=n;i++) r[i]=i; k=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++){ if(i>j){ double s=sqrt( (x[i]-x[j])*(x[i]-x[j])+ (y[i]-y[j])*(y[i]-y[j]) ); a[++k].x=i; a[k].y=j; a[k].z=s; } } scanf("%d",&m); while(m--){ scanf("%d%d",&c,&b); int aa=find_(c); int bb=find_(b); if(aa!=bb){ r[aa]=bb; } } sort(a+1,a+1+k,cmp); double ans=0; for(i=1;i<=k;i++) { int aa=find_(a[i].x); int bb=find_(a[i].y); if(aa!=bb){ r[aa]=bb; ans=ans+a[i].z; } } printf("%.2lf\n",ans); } return 0;}
0 0
- uva 10397 - Connect the Campus
- UVA 10397 - Connect the Campus
- UVa 10397 - Connect the Campus
- Uva 10397 - Connect the Campus
- UVa 10397 - Connect the Campus
- UVa 10397: Connect the Campus
- Uva - 10397 - Connect the Campus
- UVA - 10397 Connect the Campus
- UVa 10397 - Connect the Campus
- UVa 10397 Connect the Campus
- UVA 10397 - Connect the Campus
- UVa 10397 - Connect the Campus
- UVA - 10397 Connect the Campus kruskal算法
- UVA 10397 - Connect the Campus 翻译
- uva 10397 Connect the Campus kruskal || prim
- 10397 - Connect the Campus
- 10397 - Connect the Campus
- 10397 - Connect the Campus
- android webview 调用本地java代码失败解决方法
- poj 2236 Wireless NetWork
- Google Chrome误删书签的恢复方式!
- TCP连接的建立(一)
- 1009. Product of Polynomials (25)
- UVa 10397 Connect the Campus
- 第十二周项目 3 用递归方法求解(用递归方式求最大公约数)
- shell中截取字符串
- cas 4.0 单点登陆
- as3 常用正则表达式(来自天地会论坛之七夜)
- OpenCV学习的第一个实例(视屏滚动条)
- [Linux学习笔记] Zombie process
- JSP(3) - 9个JSP内置对象 - 小易Java笔记
- HDOJ-1269-迷宫城堡 解题报告