Arctic Network
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 16968   Accepted: 5412

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

Source

【题意】有S颗卫星和P个哨所,有卫星的两个哨所之间可以任意通信;否则,一个哨所只能和距离它小于等于D的哨所通信。给出卫星的数量和P个哨所的坐标,求D的最小值。
【分析】为了练练Prim。可以先用Prim把边建好,存起来,然后把选择的边从小到大排个序,第(n-p-1)个数就是答案。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include<functional>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
const int N=;
const int M=;
double edg[N][N];
double lowcost[N];//记录未加入树集合的i离树集合中元素最小的距离
int n,m,t,v;
double d[N];
bool cmp(double a,double b){
return a<b;
}
struct man
{
double x,y;int num;
}a[N];
double fun(man a,man b)
{
double cnt=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
return cnt;
}
void Build()
{
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
edg[i][j]=edg[j][i]=fun(a[i],a[j]);
}
}
}
void prim()
{
double sum=;lowcost[]=-;
for(int i=;i<n;i++){
lowcost[i]=edg[][i];
}
for(int i=;i<n;i++){
double minn=inf;int k;
for(int j=;j<n;j++){
if(lowcost[j]!=-&&lowcost[j]<minn){
k=j;minn=lowcost[j];
}
}
sum+=minn;
d[v++]=minn;
lowcost[k]=-;
for(int j=;j<n;j++){
lowcost[j]=min(lowcost[j],edg[k][j]);
}
}
sort(d,d+v,cmp);
printf("%.2lf\n",d[n-m-]);
}
int main() {
scanf("%d",&t);
while(t--) {
memset(edg,,sizeof(edg));
memset(lowcost,,sizeof(lowcost));
memset(d,,sizeof(d));
v=;
scanf("%d%d",&m,&n);
for(int i=;i<n;i++){
scanf("%lf%lf",&a[i].x,&a[i].y);
a[i].num=i;
}
Build();
prim();
}
return ;
}

POJ2349 Arctic Network(Prim)的更多相关文章

  1. [Poj2349]Arctic Network(二分,最小生成树)

    [Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...

  2. [poj2349]Arctic Network(最小生成树+贪心)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17758   Accepted: 5646 D ...

  3. POJ2349 Arctic Network 2017-04-13 20:44 40人阅读 评论(0) 收藏

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19113   Accepted: 6023 D ...

  4. POJ-2349 Arctic Network(最小生成树+减免路径)

    http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...

  5. POJ2349 Arctic Network

    原题链接 先随便找一棵最小生成树,然后贪心的从大到小选择边,使其没有贡献. 显然固定生成树最长边的一个端点安装卫星频道后,从大到小选择边的一个端点作为卫星频道即可将该边的贡献去除. 所以最后的答案就是 ...

  6. poj2349 Arctic Network - 最小生成树

    2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...

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

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

  8. 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 ...

  9. poj 2349 Arctic Network

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

随机推荐

  1. 停课day1

    一早上只做了一个calculator 还是参照题解,好惭愧 f[1]=0; flag[1]=true;    for (int i=2,N=num[n];i<p;i++) {        fo ...

  2. D. Equalize the Remainders (set的基本操作)

    D. Equalize the Remainders time limit per test 3 seconds memory limit per test 256 megabytes input s ...

  3. idea 导入spring 源码注意的问题

    问题:idea导入spring 源码的步骤是: 首先从官网下载spring的源码:git clone https://github.com/spring-projects/spring-framewo ...

  4. <video>标签的特性

    以前的网页视频 过去还没有HTML5的时候,我们处理网页视频的时候,都是通过Flash插件来实现的,然而,并非所有浏览器都有同样的插件. 现在有了HTML5带来的video元素,开发者能够很方便地将视 ...

  5. hive 动态分区(Dynamic Partition)异常处理

    Changing Hive Dynamic Partition Limits Symptoms: Hive enforces limits on the number of dynamic parti ...

  6. mycat 管理MySQL5.7主从搭建

    1.首先安装MySQL ab: 192.168.6.163 master 192.168.6.167 slave master: vi /etc/opt/rh/rh-mysql57/my.cnf.d/ ...

  7. Java节假日算法

    类:Vacation package test; import java.io.Serializable; import java.util.Date; public class Vacation i ...

  8. mysql 基本操作练习

    ), sex ), age )); , '北京'); , '上海'); , '广州'); , '北京'); , '北京'); , '上海'); , '北京'); #(). 写出sql语句,查询所有年龄 ...

  9. Flink源码阅读(一)--Checkpoint触发机制

    Checkpoint触发机制 Flink的checkpoint是通过定时器周期性触发的.checkpoint触发最关键的类是CheckpointCoordinator,称它为检查点协调器. org.a ...

  10. thinkphp 导入微信小程序加密解密库

    第三方类库 第三方类库指除了 ThinkPHP 框架.应用项目类库之外的其他类库,一般由第三方系统或产品提供,如 Smarty.Zend 等系统的类库等. 前面使用自动加载或 import 方法导入的 ...