POJ 2349 Arctic Network (最小生成树)
来源:互联网 发布:京东联盟和淘宝联盟 编辑:程序博客网 时间:2024/06/10 20:50
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.
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
1
2 4
0 100
0 300
0 600
150 750
Sample Output
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
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题目描述简直一片混乱,最后自己根据实际情况猜测的题意,有s个卫星通信设备(注意:不是卫星!)有p个前哨站,现在有两种方式可以实现通信,一种是两个前哨站之间用卫星通信设备通信,这一种没有距离的限制,第二种是通过无线广播通信,这一种有距离限制,最远为d。d越大建造成本越高,为了维修采购方便,要求所有前哨站的无线广播设备都是相同的,即d是相同的,求一个最小的d,保证每个前哨站连通。
先求出最小生成树,边由小到大排序,让边权值大的用卫星设备通信,这样s个卫星设备就代替了s-1条边,之后再找最大的边就是答案。
#include <cstdio>#include <cstring>#include <vector>#include <queue>#include <algorithm>#include <cmath>using namespace std;const int M = 505;const int INF = 0x3f3f3f3f;struct Node{double x, y;}outpost[M];struct Edge{int u, v;double w;};vector<Edge> edge;bool cmp(Edge a, Edge b){return a.w < b.w;}vector<double> tree;int pre[M];int Find(int x){int r = x;while(pre[r]!=r)r = pre[r];int i = x, j;while(pre[i]!=r){j = pre[i];pre[i] = r;i = j;}return r;}int main(){int s, p, t;Edge tmp;double dis;scanf("%d", &t);while(t--){tree.clear();edge.clear();scanf("%d%d", &s, &p);for(int i=1;i<=p;i++){scanf("%lf%lf", &outpost[i].x, &outpost[i].y);pre[i] = i;}for(int i=1;i<=p;i++)for(int j=i+1;j<=p;j++){dis = sqrt((outpost[i].x-outpost[j].x)*(outpost[i].x-outpost[j].x) + (outpost[i].y-outpost[j].y)*(outpost[i].y-outpost[j].y));tmp.u = i;tmp.v = j;tmp.w = dis;edge.push_back(tmp);}sort(edge.begin(), edge.end(), cmp);int cnt = 0;vector<Edge>::iterator it;for(it=edge.begin(); it!=edge.end();it++){if(Find(it->u)!=Find(it->v)){tree.push_back(it->w);cnt++;pre[Find(it->u)] = Find(it->v);}if(cnt == p-1)break;}printf("%.2f\n", tree[p-1-s]);}return 0;}
阅读全文
0 0
- POJ 2349 Arctic Network [最小生成树]
- poj 2349 (最小生成树)Arctic Network
- POJ-2349 Arctic Network 最小生成树
- POJ 2349 Arctic Network 最小生成树
- poj-2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树
- poj 2349 Arctic Network 最小生成树~~
- Arctic Network (poj 2349 最小生成树)
- POJ 2349Arctic Network【最小生成树】
- 【最小生成树】POJ 2349 Arctic Network
- POJ 2349 Arctic Network 最小生成树
- POJ-2349-Arctic Network [最小生成树]
- POJ 2349 Arctic Network (最小生成树)
- POJ 2349 Arctic Network (最小生成树)
- POJ Arctic Network 【最小生成树】
- Arctic Network--POJ(最小生成树)
- poj 2349 Arctic Network(最小瓶颈生成树)
- ubuntu卸载某个package失败的处理方法
- 信息论基础
- 2017 Multi-University Training Contest 4 1003 || HDU6069
- 使用jQuery实现点击左右滑动切换特效
- 使用java写一个hello world
- POJ 2349 Arctic Network (最小生成树)
- SpringBoot之配置中心服务化和高可用
- 手机端页面自适应解决方案—rem布局进阶版(附源码示例)
- Java中的深拷贝与浅拷贝
- UVA 1339
- VS2015 没有打包工具
- Servlet运行原理
- 利用headset profile实现语音采集
- 深入理解JVM—JVM内存模型