Arctic Network
Time Limit: 2000MS | Memory Limit: 65536K |
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
1 2 4 0 100 0 300 0 600 150 750
Sample Output
212.13————————————————————集训9.5的分割线————————————————————
前言:数死早。。。一开始把(0,100)画成了(100,0),死都看不懂样例。其实题意很简单。
思路:假如先不看卫星频道。每个点都有无线电收发器,距离为D,就是要求出最小生成树上最大的边权值。有了k个卫星频道,就可以消除k - 1条边。把最小生成树上所有的边。排个序,舍弃最长的k - 1个边就行了。因为稠密图,所以Prim。
代码如下:
/*
ID: j.sure.1
PROG:
LANG: C++
*/
/****************************************/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#define INF 2e9
using namespace std;
/****************************************/
const int N = 505;
int n, fm, cnt;
struct Point
{
int x, y;
}node[N];
double low[N], dis[N][N], ans[N];
void prim()
{
cnt = 0;
for(int i = 0; i < n; i++)
low[i] = dis[0][i];
low[0] = -1;
int k;
for(int i = 1; i < n; i++) {
double mini = INF;
for(int j = 0; j < n; j++) if(low[j] != -1) {
if(mini > low[j]) {
k = j;
mini = low[j];
}
}
ans[cnt++] = mini;
low[k] = -1;
for(int j = 0; j < n; j++) if(low[j] != -1) {
low[j] = min(low[j], dis[k][j]);
}
}
}
int main()
{
#ifdef J_Sure
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
#endif
int T;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &fm, &n);
for(int i = 0; i < n; i++) {
scanf("%d%d", &node[i].x, &node[i].y);
}
for(int i = 0; i < n; i++) {
for(int j = i + 1; j < n; j++) {
dis[i][j] = dis[j][i] = sqrt(1.0 * ((node[i].x - node[j].x)*(node[i].x - node[j].x)
+ (node[i].y - node[j].y)*(node[i].y - node[j].y)));
}
}
prim();
sort(ans, ans+cnt);
printf("%.2f\n", ans[n-fm-1]);
}
return 0;
}