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

题目意思:有P个哨所和S个卫星,要建立所有哨所之间的联系。有卫星的两个哨所之间可以任意通信;否则一个哨所只能和距离它小于等于D的哨所通信。给出P个哨所的坐标,求D的最小值。
解题思路:为了使这P个哨所建立起联系,我们需要树状图,所以需要使用最小生成树的算法,将所有点建立起联系。但是为了所得到的D最小,对于最小生成树种那些边长较长的边,我们可以使用卫星进行联系,有S个卫星,这样就将最小生成树划分为了S个割集,割集之间使用卫星联系,割集之内使用无线联系,求割集内的点之间的最大值即为最小的D。
 #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxs 550
using namespace std;
int pre[maxs];
int m,k;
int s,p;
double dis[maxs*maxs];
struct node///各个哨所的坐标
{
int x;
int y;
} a[maxs];
struct edge///哨所之间联系构成边
{
int u;
int v;
double w;
} e[maxs*maxs];
bool my_cmp(edge a,edge b)
{
return a.w<b.w;
}
bool my_cmp2(double a,double b)
{
return a>b;
}
double Getdis(node a,node b)///获得各个边的距离
{
return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y));
}
int Find(int x)
{
if(x!=pre[x])
{
pre[x]=Find(pre[x]);
}
return pre[x];
}
void Union(int a,int b)
{
int x=Find(a);
int y=Find(b);
if(x>y)
{
pre[x]=y;
}
else
{
pre[y]=x;
}
}
void Kruskal()
{
memset(dis,0.0,sizeof(dis));
int i,counts;
counts=;
for(i=; i<=m; i++)
{
int fx=Find(e[i].u);
int fy=Find(e[i].v);
if(fx!=fy)
{
pre[fx]=fy;
counts++;
dis[counts]=e[i].w;
if(counts==p-)///p个点,p-1条边
{
break;
}
}
}
sort(dis+,dis+counts+,my_cmp2);
printf("%.2f\n",dis[s]);///最小的D为所有边中排除前S大后最大的那一个
}
int main()
{
int t,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&s,&p);
for(i=; i<=p; i++)
{
pre[i]=i;
}
m=;
for(i=; i<=p; i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
}
for(i=; i<=p; i++)
{
for(j=i+; j<=p; j++)
{
m++;
e[m].u=i;
e[m].v=j;
e[m].w=Getdis(a[i],a[j]);
}
}
sort(e+,e+m+,my_cmp);
Kruskal();
}
return ;
}
 

Arctic Network POJ 2349 (最小生成树思想)的更多相关文章

  1. (最小生成树) Arctic Network -- POJ --2349

    链接: http://poj.org/problem?id=2349 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 1371 ...

  2. Arctic Network POJ - 2349

    The Department of National Defence (DND) wishes to connect several northern outposts by a wireless n ...

  3. POJ2349:Arctic Network(二分+最小生成树)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 28311   Accepted: 8570 题 ...

  4. POJ 2349 Arctic Network(贪心 最小生成树)

    题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...

  5. poj 2349(最小生成树应用)

    题目链接:http://poj.org/problem?id=2349 思路:由于有S个专门的通道,我们可以先求一次最小生成树,然后对于最小生成树上的边从大到小排序,前S-1条边用S-1个卫星通道连接 ...

  6. POJ 2349 Arctic Network (最小生成树)

    Arctic Network Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  7. POJ 2349 Arctic Network (最小生成树)

    Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...

  8. poj 2349 Arctic Network

    http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submis ...

  9. POJ - 2349 ZOJ - 1914 Arctic Network 贪心+Kru

    Arctic Network The Department of National Defence (DND) wishes to connect several northern outposts ...

随机推荐

  1. 在TextBrowser显示中,如何让最新的数据永远出现在第一行或者是在窗口的最后显示信息

    这是第一行,但是随着数据的增多,最新的数据就会在末尾显示,然后就看不到了.可以用 main_ui->ReceiveDatatextBrowser->insertPlainText(strD ...

  2. 使用tp3.2和mbUploadify.js上传图片的代码,记录一下

    HTML: <div class="form-group"> <label class="col-sm-1 control-label no-paddi ...

  3. windows7平台 nginx+python 环境搭建

    参考了这篇文章,感谢原文作者:https://blog.csdn.net/foxgod/article/details/78929201 最近正在学习Python,发现除了写一点py脚本在idlex上 ...

  4. c#开发微信公众号——关于c#对象与xml的转换

    在成为微信公众号开发者以后,整个交互流程:用户->微信服务器->自己的服务器->返回微信服务器->用户: 举个例子:用户在微信公众号里面发了个“您好!”,微信服务器会以特定的x ...

  5. 树莓派3B+SimpleCV上连接iPhone4s摄像头

    目的:把iPhone4s当成网络摄像头,通过wifi连接到树莓派上,做为树莓派的摄像头. 1. iPhone4s上安装mini WebCam应用. 很旧的一个app, 没有密码,简单,无广告,免费. ...

  6. string函数库的原型

    #ifndef __HAVE_ARCH_STRCPY /** * strcpy - Copy a %NUL terminated string * @dest: Where to copy the s ...

  7. anaconda创建python虚拟环境

    参考: 1.https://blog.csdn.net/lyy14011305/article/details/59500819 我的安装过程: 1. 之前已经安装了anaconda,我的版本是ana ...

  8. Burp 之Intruder

    攻击类型: (1)Sniper:测试完第一个变量后,就测试下一个变量,一次向下测试,每次只测试一个变量 适用于单变量 (2)Battering ram:只有一个payload,该payload会同时测 ...

  9. 加分项——C语言实现Linux的pwd命令

    加分项--C语言实现Linux的pwd命令 实现要求 1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试mypwd pwd pw ...

  10. vim 多个文件切换

    打开多个文件:1.vim还没有启动的时候:在终端里输入 vim file1 file2 ... filen便可以打开所有想要打开的文件2.vim已经启动输入:open file可以再打开一个文件,并且 ...