POJ 2349 ——Arctic Network(kruskal)
来源:互联网 发布:数学建模与算法的关系 编辑:程序博客网 时间:2024/06/04 19:43
Description
The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used in establishing the network: every outpost will have a radio transceiver and some outposts will in addition have a satellite channel.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Any two outposts with a satellite channel can communicate via the satellite, regardless of their location. Otherwise, two outposts can communicate by radio only if the distance between them does not exceed D, which depends of the power of the transceivers. Higher power yields higher D but costs more. Due to purchasing and maintenance considerations, the transceivers at the outposts must be identical; that is, the value of D is the same for every pair of outposts.
Your job is to determine the minimum D required for the transceivers. There must be at least one communication path (direct or indirect) between every pair of outposts.
Input
The first line of input contains N, the number of test cases. The first line of each test case contains 1 <= S <= 100, the number of satellite channels, and S < P <= 500, the number of outposts. P lines follow, giving the (x,y) coordinates of each outpost in km (coordinates are integers between 0 and 10,000).
Output
For each case, output should consist of a single line giving the minimum D required to connect the network. Output should be specified to 2 decimal points.
Sample Input
12 40 1000 3000 600150 750
Sample Output
212.13#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;int n,k,x[1001],y[1001],idx,f[1001],s[1001],how,S;struct node{int a,b,len;}w[200001];bool com(const node &g,const node &h){return g.len<h.len;}int find(int p){if(f[p]!=p)f[p]=find(f[p]);return f[p];}void merge(int z,int v){int fx=find(z);int fy=find(v);how--;if(s[fx]>s[fy])f[fy]=fx,s[fx]+=s[fy];elsef[fx]=fy,s[fy]+=s[fx];}int main(){scanf("%d",&n);while(n--){scanf("%d%d",&S,&k);how=k;idx=0;for(int i=1;i<=k;i++){scanf("%d%d",&x[i],&y[i]);f[i]=i,s[i]=1;}for(int i=1;i<=k;i++){for(int j=1;j<i;j++){w[++idx].len=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);w[idx].a=i;w[idx].b=j;}}sort(w+1,w+idx+1,com);for(int i=1;i<=idx;i++){if(find(w[i].a)==find(w[i].b))continue;merge(w[i].a,w[i].b);if(how==S){printf("%.2lf\n",sqrt(double(w[i].len)));break;}}}}
AC 顶一个
阅读全文
3 0
- POJ 2349 ——Arctic Network(kruskal)
- POJ 2349 Arctic Network(Prim/Kruskal)
- poj 2349 Arctic Network (kruskal)
- POJ 2349 Arctic Network (Kruskal) .
- [POJ 2349] Arctic Network Kruskal
- POJ 2349(Kruskal) Arctic Network
- Arctic Network(POJ 2349)(最小生成树Kruskal)
- Arctic Network (Kruskal)
- poj 2349 Arctic Network 【最小生成树-Kruskal】
- POJ 2349 Arctic Network+Kruskal最小生成树
- POJ 2349 Arctic Network(Kruskal求最小生成树第k条边的长度)
- 文章标题 POJ 2349:Arctic Network ( 最小生成树Kruskal算法+并查集)
- POJ 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- poj 2349 Arctic Network
- POJ 2349 Arctic Network
- poj 2349 Arctic Network
- hpuQAQ & 火星情报局
- 局部变量, 成员变量, 类变量的区别
- 网络爬虫之cheerio
- JavaScript中的严格模式
- 24点游戏算法
- POJ 2349 ——Arctic Network(kruskal)
- MyBatis工具:基础CRUD封装
- 深度学习入门
- Mybatis模糊查询
- 算法与数据结构-单向链表的直接插入排序和快速排序
- 从尾到头打印链表
- aop之动态代理
- Python if语句
- 【XSY2534】【CF835D】Palindromic characteristics 回文自动机