POj 2349 Arctic Network
来源:互联网 发布:淘宝网中年女装春装 编辑:程序博客网 时间:2024/05/22 22:34
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.
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
在g++下只有%f能过,真是服气,就是一个简单的最下生成树,直接用kruskal或者prim跑一下,输出连接边的第s大的边就行
代码如下:
#include<cstdio>#include<iostream>#include<cmath>#include<algorithm>#include<cstring>#include<string>using namespace std;const int MAX_V = 550;int pre[MAX_V];int x[MAX_V],y[MAX_V];int pos[MAX_V];int s,p;struct Edge{ int x,y,z;}q[MAX_V*MAX_V];int Find(int x){ int r = x; while(pre[r] != r) r = pre[r]; int i = x,j; while(i != r){ j = pre[i]; pre[i] = r; i = j; } return r;}bool add(int x,int y){ int fx = Find(x),fy = Find(y); if(fx != fy){ pre[fx] = fy; return true; } return false;}bool cmp(Edge a,Edge b){ return a.z < b.z;}int main(void){ int t; scanf("%d",&t); while(t--){ scanf("%d %d",&s,&p); for(int i=1;i<=p;i++){ scanf("%d %d",&x[i],&y[i]); } int top = 0; for(int i=1;i<=p;i++){ for(int j=i+1;j<=p;j++){ int dis = pow(x[i]-x[j],2)+pow(y[i]-y[j],2); q[++top] = (Edge){i,j,dis}; } } for(int i=1;i<=p;i++) pre[i] = i; int Count = 0,tt = 0; sort(q+1,q+1+top,cmp); for(int i=1;i<=top;i++){ if(add(q[i].x,q[i].y)){ Count++; pos[++tt] = i; } if(Count == p-1) break; } tt -= (s-1); printf("%.2f\n",sqrt(q[pos[tt]].z));//就是这里,真是服气 } return 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
- 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
- POJ-2349-Arctic Network
- poj 2349 Arctic Network
- oracle数据库一个文本框输入多种条件的查询
- 算法与数据结构-数组/链表/堆/栈/队列的存储
- 超详细,用canvas在微信小程序上画时钟教程
- iOS开发中.pch 文件的使用及其相关工程设置
- 汇编语言入门六:流程控制(二)
- POj 2349 Arctic Network
- Mybatis SqlSessionTemplate 源码解析
- 模式识别与机器学习(一):概率论、决策论、信息论
- 子集和问题
- C++中 线程函数为静态函数 及 类成员函数作为回调函数
- java.lang.StackOverflowError at org.hibernate.collection.AbstractPersistentCollection.initialize(Ab
- matlab plot函数
- 记java项目cpu 内存过高分析
- Max and Bike CodeForces