poj 2349 Arctic Network(prime)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 25165 | Accepted: 7751 |
Description
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
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
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
任何两个有卫星信道的哨所可以通过卫星进行通信,而不管他们的位置。同时,当两个哨所之间的距离不超过D时可以通过无线电通讯,D取决于对收发器的功率。功率越大,D也越大,但成本更高。出于采购和维修的方便,所有哨所的收发器必须是相同的;也就是说,D值对每一个哨所相同。
你的任务是确定收发器的D的最小值。每对哨所间至少要有一条通信线路(直接或间接)。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
#define N 510 const double M=1e12;//定义一个大值
int p,s; struct dot //哨站结点
{
double x,y;
}d[N]; double map[N][N];
double rank[N],dst[N];//rank放最小生成树的各边长,dst放各点到MST的最近距离
int vis[N]; double dist(int i,int j)//求两点距离
{
double x,y;
x=d[i].x-d[j].x;
y=d[i].y-d[j].y; return sqrt(x*x+y*y);
} void init()
{
int i,j; memset(map,,sizeof(M));
for (i=;i<p;i++)//初始化图
{
for (j=;j<p;j++)
{
if (i==j)
{
map[i][j]=;
} else
{
map[i][j]=map[j][i]=dist(i,j);
}
}
} memset(vis,,sizeof(vis));
memset(dst,,sizeof(dst));
} //bool cmp(int i,int j)
//{
// if (rank[i]<rank[j])
// {
// return true;
// }
// return false;
//} void findans()
{
int i,j;
sort(rank,rank+p-);//按增序排列,注意排序范围为rank+p-1,因为MST只有p-1条边
printf("%.2f\n",rank[p-s-]);// (p-1)-(s-1)-1,因为序号从0开始 // for (i=0;i<p;i++)
// {
// for (j=0;j<p;j++)
// {
// printf("%10.2f",map[i][j]);
// }
// printf("\n");
// }
// printf("\n");
// for (i=0;i<p-1;i++)
// {
// printf("%10.2f",rank[i]);
// }
} void prime()
{
int cnt=,k,j,point,i;
double min; vis[]=;//把0点放入MST
for (i=;i<p;i++)//初始化dst
{
dst[i]=map[i][];
} for (i=;i<p;i++)//找距MST最近的点
{
min=M;
for (j=;j<p;j++)
{
if (vis[j]==&&min>dst[j])
{
min=dst[j];
point=j;
}
} // if (min==M)
// {
// break;
// } vis[point]=;
rank[cnt++]=min; for (k=;k<p;k++)//更新各点到MST的最小距离
{
if (vis[k]==&&dst[k]>map[k][point])
{
dst[k]=map[k][point];
}
}
}
findans();
} int main()
{
int i,n,j;
double x,y; scanf("%d",&n);
for (i=;i<n;i++)
{
scanf("%d%d",&s,&p); for (j=;j<p;j++)
{
scanf("%lf%lf",&d[j].x,&d[j].y);
} init();
prime();
} return ;
}
poj 2349 Arctic Network(prime)的更多相关文章
- POJ 2349 Arctic Network (最小生成树)
Arctic Network 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/F Description The Departme ...
- POJ 2349 Arctic Network(最小生成树中第s大的边)
题目链接:http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to c ...
- POJ 2349 Arctic Network(贪心 最小生成树)
题意: 给定n个点, 要求修p-1条路使其连通, 但是现在有s个卫星, 每两个卫星可以免费构成连通(意思是不需要修路了), 问修的路最长距离是多少. 分析: s个卫星可以代替s-1条路, 所以只要求最 ...
- POJ 2349 Arctic Network(最小生成树,第k大边权,基础)
题目 /*********题意解说——来自discuss——by sixshine**************/ 有卫星电台的城市之间可以任意联络.没有卫星电台的城市只能和距离小于等于D的城市联络.题 ...
- 2349 Arctic Network(中文版)
试题描述: 国防部希望通过无线网络连接几个北方前哨基地. 在建立网络时将使用两种不同的通信技术:每个前哨基站都将拥有无线电收发器,另外还有一些前哨卫星通道. 任何带卫星频道的两个前哨都可以通过卫星进行 ...
- poj 2349 Arctic Network
http://poj.org/problem?id=2349 Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submis ...
- POJ 2349 Arctic Network (最小生成树)
Arctic Network Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- Poj 2349 Arctic Network 分类: Brush Mode 2014-07-20 09:31 93人阅读 评论(0) 收藏
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9557 Accepted: 3187 De ...
- POJ 2349 Arctic Network(最小生成树+求第k大边)
题目链接:http://poj.org/problem?id=2349 题目大意:有n个前哨,和s个卫星通讯装置,任何两个装了卫星通讯装置的前哨都可以通过卫星进行通信,而不管他们的位置. 否则,只有两 ...
随机推荐
- C++课堂作业(2)
github的链接: https://github.com/deepYY/object-oriented/tree/master/PAT.1025 题目 给定一个常数K以及一个单链表L,请编写程序将L ...
- SQL脚本修改表结构
SQL脚本修改表结构 新建表:create table [表名]([自动编号字段] int IDENTITY (1,1) PRIMARY KEY ,[字段1] nVarChar(50) default ...
- Jenkins获取编译状态
背景:在通过python的API调用Jenkins,启动Jenkins的job任务时,是需要知道Jenkins的编译状态,获取编译状态为 status=server.get_build_info(jo ...
- Scala 经典的模式匹配和尾递归
Scala 经典的模式匹配和尾递归 package io import java.io.{BufferedWriter, File, FileWriter} import java.text.Simp ...
- js事件的机制
1.html事件处理程序 <button id="btn1" onclick="alert(1);">按钮1</button> 2.do ...
- 3、Spring Cloud - Eureka(构建服务端/客户端)
3.1.Eureka简介 3.1.1.什么是 Eureka 和Consul.Zookeeper 类似, Eureka 是一个用于服务注册和发现的组件,最开始主要应用 于亚马逊公司旗下的云计算服务平台 ...
- const引用和constexpr
1.const指针 eg: (1) int const * p = nullptr; p = new int[10]; p[3] = 4; //error 我们发现第三行没法编译,这是因为第一行的c ...
- QTP基本方法2------截取字符串
1.instr: 返回字符串在另外一个字符串中第一次出现的位置 结构:instr([start],string1,string2[,compare]) start:开始位置,可选参数,默认为1 str ...
- java 常用类2
1.1 日期时间类 时间戳(timestamp):距离特定时间的时间间隔. 计算机时间戳是指距离历元(1970-01-01 00:00:00:000)的时间间隔(ms). 计算机中时间2019-04- ...
- 定义一个类Point,代表一个点,public属性有x和y,方法有显示点坐标 show(),构造函数有两个参数分别给x,y赋值,在main方法中构造两个对象,再创建一方法(getMiddle)为取两个点构成线段的中点的坐标,参数为2个点对象,调用此方法后得到一个新的点,编写Application,显示该对象的坐标值。
这个题让我更加明白了类创建对象的实质 代码中用到:1.对象作形参;2.对象作返回值 以下用代码具体分析: class Point1{ public double x; public double y; ...