hdu 1162
来源:互联网 发布:js注释 编辑:程序博客网 时间:2024/05/17 00:56
点击打开链接//保留两位小数//kruskal 并查集#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>using namespace std;typedef pair<double,double>PII;const int maxe=6000+5;const int maxv=100+5;struct Edge{int from,to;double weight;};bool operator<(const Edge&E1,const Edge&E2){ return E1.weight<E2.weight;}Edge edges[maxe];int parent[maxv];PII num[maxv];int find(int x){ return x==parent[x]?x:parent[x]=find(parent[x]);}int main(){ int v; while(scanf("%d",&v)==1) { for(int i=0;i<v;i++) { cin>>num[i].first>>num[i].second; } for(int i=1;i<=v;i++) parent[i]=i; int ans=0; for(int i=0;i<v-1;i++) for(int j=i+1;j<v;j++) { edges[ans].from=i+1; edges[ans].to=j+1; edges[ans].weight=hypot(num[i].first-num[j].first,num[i].second-num[j].second); ans++; } sort(edges,edges+ans); double sum=0; for(int i=0;i<ans;i++) { int p1=find(edges[i].from); int p2=find(edges[i].to); if(p1==p2) continue; parent[p1]=p2; sum+=edges[i].weight; } printf("%.2f\n",sum); } return 0;}
阅读全文
0 0
- hdu 1162
- hdu 1162
- HDU 1162
- hdu 1162
- hdu-1162
- hdu 1162
- hdu 1162
- hdu 1162
- hdu 1162 prim算法
- hdu 1162(Kruskal)
- hdu 1162 prim模板
- HDU 1162 Prim
- hdu 1162 kruscal
- hdu 1162 Prim
- hdu
- hdu
- HDU
- hdu ()
- android-studio 复制项目到新的路径 Installation fail问题解决
- POJ 1741 Tree——点分治
- 不得不知的Android线程管理
- 电商商家后台-easyUI的combox三级联动
- ActiveMQ(6)-基于networkConnector的Broker-Cluster方案
- hdu 1162
- 6-11 判断奇偶性
- Netty实战手册(一)
- android studio 3.0 升级问题:原来module中的包没法引用
- linux中ftp提示--553 Could not create file
- 彻底解决 LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 最近我的VS2010不知道怎么回事,平时用的好好的,近期竟然出现了所谓的 L
- 子网划分
- 写在自动化测试之前,我们要做哪些准备?
- JavaWeb——jdbc与dbcp数据库连接