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. Model验证简单易懂

    public bool UserSex { get; set; } //定义名字 [Display(Name = "年龄")] [Range(0, 150, ErrorMessag ...

  2. Ubuntu16.04安装TensorFlow

    1.查看tensoflow与CUDA对应版本: windows端:https://tensorflow.google.cn/install/source_windows Linux端:https:// ...

  3. 修复 Cydia 不能上网的问题

    使用 h3lix 越狱 10.3.3 的 iPhone5,进入 Cydia 不能联网解决方法:打开 Cydia,进入已安装列表,点击 Cydia Installer 卸载,然后看到桌面上就没有 Cyd ...

  4. 移动端H5页面解决软件键盘把页面顶起

    在input失去焦点的时候加上强制页面归位 window.scroll(0,0); 上代码 <input data-component="SearchInput" type= ...

  5. 如何安装使用MinDoc搭建个人在线wiki文档

    MinDoc是什么? MinDoc是一个在线的文档管理系统,该系统适用于团队.个人等使用.开发者最初的目的是为了便于公司内部使用,仿照看云开发.有laravel版本以及golang版本.不过larav ...

  6. Flume(4)-监控模型

    一. 监控端口数据 首先启动Flume任务,监控本机44444端口,服务端: 然后通过netcat工具向本机44444端口发送消息,客户端: 最后Flume将监听的数据实时显示在控制台. 1. 安装n ...

  7. linux-2.6.22.6内核启动分析之配置

    配置过程最终结果是生成.config文件,我们想要对配置的目的有很清楚的了解,必须先对.config文件进行分析.通过cd命令切换到linux-2.6.22.6内核目录,输入vi .config 可以 ...

  8. 第二篇:shell基础命令(部分)

    目录 一.shell命令规则 二.基础命令详解(部分) ls :列出目录内容 mkdir : 创建目录 rmdir :删除目录 touch:新建文件 mv:修改文件(目录)名.移动路径 cp:复制文件 ...

  9. python从Excel中提取邮箱

    从各个城市的律师协会去爬取的律师的招聘信息,可是邮箱在招聘简介里面,所有需要写个脚本去提取邮箱 import pandas as pd import re regex = r"([-_a-z ...

  10. xss:利用编码绕过(新手向)

    当浏览器接受到一份HTML代码后,会对标签之间(<p>xxx</p>等,<script>除外).标签的属性中(<a href='xxxx'>)进行实体字 ...