poj 2349 Arctic Network
2015-08-13 20:00
351 查看
Arctic Network
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)Total Submission(s) : 15 Accepted Submission(s) : 4
Problem 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 题中说有在北极有几个地方需要保持信息连接,卫星可以任意远的两个地方连接,而无线电则有距离限制,求需要的无线电的辐射长度最小是多少! 分析下题:首先建最小树,距离远的用卫星连接,而剩下的距离中的最大值则为满足条件的无线电辐射长度!上代码:#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int per[260000],n,m; double a[260000]; struct node { int x,y; double w; }s[260000]; bool cmp(node x,node y)//排序 { return x.w<y.w; } void init() { for(int i=0;i<=n;i++) per[i]=i; } int find(int x)//查找 { int i,j,t=x; while(t!=per[t]) t=per[t]; i=x; while(i!=t) { j=per[i]; per[i]=t; i=j; } return t; } bool join(int x,int y)//合并 { int fx=find(x); int fy=find(y); if(fx!=fy) { per[fx]=fy; return true ; } return false; } int main() { int i,j,n1; scanf("%d",&n1); while(n1--) { double x[600],y[600]; scanf("%d%d",&m,&n); init(); for(i=0;i<n;i++) scanf("%lf%lf",&x[i],&y[i]); int k=0; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { s[k].x=i; s[k].y=j; s[k++].w=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); } } sort(s,s+k,cmp); int t=0; for(int i=0 ; i<k ; i++) { if(join(s[i].x,s[i].y)) a[t++]=s[i].w; } printf("%.2f\n",a[t-m]); } return 0; }
相关文章推荐
- java.lang.ClassNotFoundException: org.springframework.web.content.ContextLoaderListener
- Scala练习(十四)
- 阿里云ECSserver部署django
- 学校集训心得 DAY8.13
- C++包含函数指针的复杂定义处理办法
- 剑指offer_面试题18_树的子结构
- Android URI简介
- 超级简单的string 类型转换成char*类型的方法。
- 有哪些好的上报crash工具:推荐crashlytics
- Scala练习(十二)
- Scala练习(十一)
- BZOJ 3791 作业 DP
- 使用gem安装jekyll错误记录
- poj 3903
- 斐波那契数列
- android的camera
- 一个码农对软件项目基层人员管理的思考——会议篇
- HUNAN 11562 The Triangle Division of the Convex Polygon(大卡特兰数)
- Edittext请求输入法无效的解决方案
- 常用的正则表达式大全