Uva 10369 Arctic Network 最小生成树
来源:互联网 发布:linux source 编辑:程序博客网 时间:2024/05/18 05:10
题目大意:n个城市,s个卫星,有卫星的可以无限长度相连,其他城市间用无线电相连。问剩余城市间最大距离。
模型即最小生成树中n-s长边
#include <stdio.h>#include <string.h>#include <math.h>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int maxn = 1005;const int Mod = 1000000007;int s,n,m,c;double ans;struct Node{int x,y;}point[maxn];struct node{int u,v;double w;}edge[maxn*maxn];int p[maxn];bool cmp( node a,node b ){return a.w < b.w;}int find( int x ){return x == p[x]?x:p[x] = find( p[x] );}void merge( node s ){int x = find( s.u );int y = find( s.v );if( x != y ){p[x] = y;c ++;ans = s.w;}}int main(){#ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endifint cas;scanf("%d",&cas);while( cas -- ){scanf("%d%d",&s,&n);ans = m = c = 0;for( int i = 1; i <= n; i ++ ){scanf("%d%d",&point[i].x,&point[i].y);}for( int i = 1; i <= n; i ++ ){for( int j = i+1; j <= n; j ++ ){edge[m].u = i; edge[m].v = j;edge[m++].w = 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 ))*1.0 );}}sort( edge,edge+m,cmp );for( int i = 0; i <= n; i ++ )p[i] = i;for( int i = 0; i < m; i ++ ){merge( edge[i] );if( c == n - s )break;}printf("%.2lf\n",ans);}return 0;}
0 0
- uva 10369 - Arctic Network(最小生成树)
- UVA 10369 - Arctic Network(最小生成树)
- Uva 10369 Arctic Network 最小生成树
- UVA 10369- Arctic Network(最小生成树)
- UVA 10369Arctic Network【最小生成树】
- uva 10369 - Arctic Network(最小生成树)
- (intermediate) 最小生成树 UVA 10369 - Arctic Network
- UVA - 10369 Arctic Network (最小生成树)
- 2349 poj &&uva 10369 Arctic Network【最小生成树】
- UVA 10369 - Arctic NetWork (求最小生成树)
- UVa - 10369 - Arctic Network ( 最小生成树 Kruscal )
- UVa 10369 - Arctic Network(求最小生成树的第k小边)
- poj 2349 Arctic Network uva 10369(prim or kruscal最小生成树)
- UVa 10369 Arctic Network (Kruskal+最小生成树的第K小边)
- POJ 2349 Arctic Network [最小生成树]
- poj 2349 (最小生成树)Arctic Network
- ZOJ 1914 Arctic Network 最小生成树
- POJ-2349 Arctic Network 最小生成树
- ubuntu下安装ssh 实现远程登录工具secureCRTl连接
- Python 正则表达式验证传统日期
- Android 激活Deviceadmin,并进行锁屏和恢复出厂设置
- Crack Sublime Text 3 | Ubuntu
- 联想A800新蜂ROM V1.1 基于官方4.0.4精简省电稳定
- Uva 10369 Arctic Network 最小生成树
- 大数据架构师基础:hadoop家族,Cloudera产品系列等各种技术
- ssh2框架Struts2中action的属性配置错误问题
- canvas画图的一个坑
- 听说现在上网可以查到开房记录,我顿时就慌了,如果被人发现我从来没开过房,多难为情啊!
- php ob_start()、ob_end_flush和ob_end_clean()多级缓冲
- 待字闺中之Magic Index 分析
- source insight的查找功能
- H.264视频编码在VC++.Net中的实现