hdu1162-Eddy's picture
来源:互联网 发布:网络压力测试工具 编辑:程序博客网 时间:2024/05/01 08:41
http://acm.hdu.edu.cn/showproblem.php?pid=1162
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std; #define MAX 5050int fa[ MAX ] ;struct node{int x , y ;double value ;bool operator < (const node &T) const{return value < T.value;} }edge[ MAX ]; struct point{double x , y ;}point[ MAX ];int Union( int n ) {for( int i = 0 ; i < n ; ++i )fa[ i ] = i ;}int find( int x ) {return fa[ x ] = x == fa[ x ] ? x : find( fa[ x ] ) ;}int main(){int n ;int i , j ;while( scanf( "%d" , &n )!= EOF && n ){Union( n * n ) ;for( i = 0 ; i < n ; ++i ){scanf( "%lf%lf" , &point[ i ].x , &point[ i ].y ) ;}int k = 0 ;for( i = 0 ; i < n ; ++i ){for( j = i + 1 ; j < n ; ++j ){edge[ k ].x = i ;edge[ k ].y = j ;edge[ k ].value = (double )sqrt( ( point[ i ].x - point[ j ].x ) * ( point[ i ].x - point[ j ].x ) + ( point[ i ].y - point[ j ].y )*(point[ i ].y - point[ j ].y ) );k++ ;}}sort( edge , edge + k ) ;double sum = 0.0 ;for( i = 0 ; i < k ; ++i ){int x1 = find( edge[ i ].x ) ;int x2 = find( edge[ i ].y );if( x1 != x2 ){sum += edge[ i ].value ;fa[ x1 ] = x2 ;}}printf( "%.2lf\n" , sum ) ;}return 0 ;}
- Eddy's picture hdu1162
- Eddy's Picture(Hdu1162)
- HDU1162 Eddy's picture
- hdu1162-Eddy's picture
- hdu1162-Eddy's picture
- HDU1162:Eddy's picture
- HDU1162---Eddy's picture
- HDU1162-Eddy's picture
- HDU1162 Eddy's picture【Prim】
- HDU1162——Eddy's picture
- hdu1162 Eddy's picture(prim模板)
- HDU1162 Eddy's picture 最小生成树
- hdu1162 Eddy's picture (prim最小生成树)
- hdu1162 Eddy's picture (最小生成树之prim 算法)
- hdu1162 Eddy's picture(prim和kruskal)
- HDU1162 Eddy's picture 【最小生成树Prim】
- hdu1162 Eddy's picture 并查集+最小生成树
- HDU1162-Eddy's picture-最小生成树(prim算法模板)
- 点击背景 关闭键盘
- 编译Android 4.0.4(打包出问题)
- 单链表反转
- 写两个程序出现StackOverflowError和
- Qt实现窗口tabwidget的拖出双击弹回功能
- hdu1162-Eddy's picture
- 关于SQL时间类型的模糊查询 .
- 智力题(2)
- IOS非主线程更新界面tableview
- ubuntu 配置 git
- Java对文件进行数字签名
- MAC OS X uname command
- LINQ的优势
- omnetpp安装时的一些问题