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. form组件-字段

    Form类 创建Form类时,主要涉及到 [字段] 和 [插件],字段用于对用户请求数据的验证,插件用于自动生成HTML 1.Django内置字段如下: Field required=True, 是否 ...

  2. php无限极分类处理

    /** * 无限极分类处理(通过递归方式实现) * @param $section 原始数据Array * @param $html 界面显示前缀,比如 |- * @param $spear 分级中所 ...

  3. pyntho经典面试题

    Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的解释器 ...

  4. js对字符串进行加密和解密

    //字符串进行加密 function compileStr(code){   var c=String.fromCharCode(code.charCodeAt(0)+code.length); fo ...

  5. centos 安装 telnet

    (转)centos7安装telnet服务 场景:在进行Telnet测试时候,发现无法连接,所以还得把这个软件也安装了 1 CentOS7.0 telnet-server 启动的问题 解决方法:   先 ...

  6. 在javascript中的跨域解决

    跨域产生的原因 跨域是由浏览器的同源策略引起的,即不同源(协议,域名,端口中其中有一个不同)的js是不能读取对方的资源的.当要网站中的js要请求其他网站的数据时就会产生跨域问题,就像下面这样,浏览器会 ...

  7. Synchronized关键字与多线程

    在java中,每一个对象有且仅有一个同步锁.这也意味着,同步锁是依赖于对象而存在.当我们调用某对象的synchronized方法时,就获取了该对象的同步锁.例如,synchronized(obj)就获 ...

  8. R语言学习笔记—决策树分类

    一.简介 决策树分类算法(decision tree)通过树状结构对具有某特征属性的样本进行分类.其典型算法包括ID3算法.C4.5算法.C5.0算法.CART算法等.每一个决策树包括根节点(root ...

  9. VBox&vmware虚拟机安装Linux及Linux基础入门学习

    VBox&vmware虚拟机安装Linux及Linux基础入门学习 通过VMware workstation安装Linux 在安装虚拟机之前,我特意上网搜索了一下目前常使用的虚拟机软件,了解了 ...

  10. PostgreSQL参数学习:random_page_cost

    磨砺技术珠矶,践行数据之道,追求卓越价值回到上一级页面:PostgreSQL基础知识与基本操作索引页    回到顶级页面:PostgreSQL索引页[作者 高健@博客园  luckyjackgao@g ...