POJ 2349 Arctic Network

Arctic Network

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 18447   Accepted: 5829

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

Source

Waterloo local 2002.09.28

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<cmath>
 6 using namespace std;
 7 int T,n,tot,fa[510],x,y;
 8 const int INF=0x7fffffff;
 9 double rt[250005];
10 int mark=0;
11 struct dian{
12     double x,y;
13 }node[510];
14 struct Edge{
15     int u,v;double w;
16 }e[250005];
17 void add_edge(int u,int v,double w){
18     e[tot].u=u;e[tot].v=v;e[tot].w=w;tot++;
19 }
20 bool cmp(Edge a,Edge b){
21     return a.w<b.w;
22 }
23 void init(){
24     memset(fa,-1,sizeof(fa));
25     tot=0;
26 }
27 int find(int x){
28     if(fa[x]==-1) return x;
29     else return fa[x]=find(fa[x]);
30 }
31 void kruskal(int n){
32     double ans=0;
33     sort(e,e+tot,cmp);
34     int cnt=0;
35     for(int k=0;k<tot;k++){
36         int u=e[k].u,v=e[k].v;
37         int rx=find(u),ry=find(v);
38         if(rx!=ry){
39             rt[mark]=e[k].w;ans+=e[k].w;
40             fa[rx]=ry;mark++;cnt++;
41         }
42         if(cnt == n-1) break;
43     }
44     //if(cnt<n-1) return -1;
45     //else return ans;
46 }
47 int main()
48 {
49     scanf("%d",&T);int s;
50     while(T--){
51         init();
52         scanf("%d%d",&s,&n);
53         for(int i=1;i<=n;i++)
54           scanf("%lf %lf",&node[i].x,&node[i].y);
55         for(int i=1;i<=n;i++){
56             double d;
57             for(int j=1;j<=i;j++){
58                 if(i==j){ d=INF; }
59                 else{
60                     d=sqrt(1.0*(node[i].x-node[j].x)*
61                     (node[i].x-node[j].x)
62                     +1.0*(node[i].y-node[j].y)
63                     *(node[i].y-node[j].y));
64                 }
65                 add_edge(i,j,d);
66             }
67         }
68         kruskal(n);
69         printf("%.2f\n",rt[mark-s]);
70     }
71     return 0;
72 } 

搞了一晚上的破题终于AC了

时间: 2024-10-12 17:04:59

POJ 2349 Arctic Network的相关文章

POJ 2349 Arctic Network 最小生成树题解

本题也是使用Prime和Kruskal都可以的最小生成树的题解. 本题一点新意就是:需要除去最大的S-1个距离,因为可以使用卫星覆盖这些距离. 技巧:建图建有向图,速度快点,不用计算两边. 这里使用Prime,因为是稠密图. #include <stdio.h> #include <math.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <al

poj 2349 Arctic Network (prim算法)

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10525   Accepted: 3470 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

poj 2349 Arctic Network MST/二分答案

poj 2349 Arctic Network 题目传送 Sol: 方法一: 贪心的想,发现n个点只需要n-1条边即可,求MST即可,再把MST中最大的m-1条边去掉,第m大就是答案. code: #include<string> #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> #define IL inline #define RG register

POJ 2349 Arctic Network (最小生成树第K大(小)边)

Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13108   Accepted: 4256 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication tec

poj 2349 Arctic Network(最小生成树的第k大边证明)

题目链接: http://poj.org/problem?id=2349 题目大意: 有n个警戒部队,现在要把这n个警戒部队编入一个通信网络, 有两种方式链接警戒部队:1,用卫星信道可以链接无穷远的部队. 2,用信号收发器可以链接周围d米以内的部队. 现在有s个卫星信道,问d最小是多少时能连接全部的警戒部队? 解题思路: 我是用求最小生成树,记录路径长度,对路径长度排序后,第k长的边就是答案, 但是队友是用最小k度限制生成树,因为我的方法它证明不了,也推翻不了~~~~, 最后我下去仔细想了想反证

POJ 2349 Arctic Network(最下生成树+求第k大边)

题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两个前哨之间的距离不超过D,才能通过无线电进行通信.求出能使所有前哨都能直接或间接通信的最小的D. 解题思路:题目要求使所有前哨都能直接或间接通信,那么相当于使n个点相连,至少需要n-1条边.可以将n个点分为s个团,每个团内部时无限通信,团与团之间通过卫星通信.那么就相当于用s个卫星装置建立s-1条边

POJ 2349 Arctic Network (最小生成树)

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 a

poj 2349 Arctic Network(prime)

Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25165   Accepted: 7751 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are t

2349 Arctic Network(中文版)

试题描述: 国防部希望通过无线网络连接几个北方前哨基地. 在建立网络时将使用两种不同的通信技术:每个前哨基站都将拥有无线电收发器,另外还有一些前哨卫星通道. 任何带卫星频道的两个前哨都可以通过卫星进行通信,无论其位置如何. 否则,只有两个前哨基站之间的距离不超过D,才能通过无线电通信,这取决于收发器的功  率.  更高的功率产生更高的D,但成本更高. 由于采购和维护的考虑,前哨收发器必须相同; 也就是说,D的价值对于每对前哨都是一样的. 您的工作是确定收发器所需的最小D. 在每对前哨之间必须至少