hdu4463-Outlets
来源:互联网 发布:淘宝童装轮播图素材 编辑:程序博客网 时间:2024/05/21 08:02
http://acm.hdu.edu.cn/showproblem.php?pid=4463
// File Name: hdu4463.cpp// Author: bo_jwolf// Created Time: Thursday, May 09, 2013 PM01:06:34 HKT#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<stack>#include<queue>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<sstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>using namespace std;const int maxn = 10005 ;int mapp[ 105 ][ 105 ] ;int fa[ maxn ] ;struct node{int x , y ;double dis ;}edge[ maxn ] ;struct Point{double xi , yi ;}point[ maxn ] ;int cmp( node a , node b ){return a.dis < b.dis ;}double point_dis( Point a ,Point b ){return sqrt( ( a.xi - b.xi ) * ( a.xi - b.xi ) + ( a.yi -b.yi ) * ( a.yi - b.yi ) ) ;}int find( int x ){return fa[ x ] = x==fa[ x ] ? x : find( fa[ x ] ) ;}int main(){int n ;while( scanf( "%d" , &n ) != EOF && n ){int p , q;scanf( "%d%d" , &p , &q );//memset( fa , 0 , sizeof( fa ) ) ;for( int i = 0 ; i < maxn ; i++ )fa[ i ] = i ;for( int i = 1 ; i <= n ; i++ )scanf( "%lf%lf" , &point[i].xi , &point[i].yi ) ;int k = 0 ;for( int i = 1 ; i <= n ; i++ )for( int j = i + 1 ; j <= n ; j++ ){edge[ k ].x = i ;edge[ k ].y = j ;edge[ k ].dis = point_dis( point[ i ] , point[ j ] ) ;if( ( i == p && j == q ) || ( i == q && j == p ) )edge[ k ].dis = 0 ;k++;}sort( edge , edge + k , cmp ) ;double ans = point_dis( point[ p ] , point [ q ] );int sum = 0;for( int i = 0 ; i <= k ; i++ ){int x1 = find ( edge[ i ].x );int x2 = find ( edge[ i ].y );if( x1 != x2 ){fa[ x1 ] = x2 ;ans += edge[ i ].dis ;sum++ ;if( sum == n - 1)break;}}printf( "%.2lf\n" , ans ) ;}return 0;}
- hdu4463-Outlets
- hdu4463 Outlets
- HDU4463-Outlets
- HDU4463-Outlets
- hdu4463 Outlets
- hdu4463 Outlets(prim算法)
- hdu4463 Outlets 最小生成树
- 并查集-HDU4463-Outlets
- hdu4463 Outlets(必含某条边的最小生成树)
- HDU4463-Outlets,简单最小生成树。1A水过~~
- hdu4463
- Outlets
- Outlets
- Outlets and Reference Outlets
- Electrical Outlets
- 2013资料整理-Outlets与Referencing Outlets
- Outlets 和Referencing Outlets的区别
- Outlets 和Referencing Outlets的区别
- Android NDK开发的环境配置和使用
- extjs中的事件注册和调用顺序
- 小巧的编辑器Gnu nano-------入门篇
- 超顺滑!优化android ListView拖拽移位
- HP Unix 11.11 安装jdk15:
- hdu4463-Outlets
- MPEG-2视频编码方式
- cocos2d-x cocosBuilder
- ios 正则表达式 去标点 只含数字 字母 汉字 空格
- Linux上配置sendmail
- android优化
- SecureCRT 快捷键
- opendir----打开目录函数
- 提升HBase性能的几个地方