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. 2018-2-6考试(COCI2014/2015 Contest#5)

    T1:FUNGHI(1s,32M,50pts)得分:50 题意:给你8个数组成一个环,要你求出其中连续的4个数,让它们的和最大 题解:暴力求出每一连续4个数之和,比较一下就好 标签:模拟 C++ Co ...

  2. 【bzoj2756 奇怪的游戏】

    Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 4403  Solved: 1226[Submit][Status][Discuss] Descript ...

  3. HDU3338:Kakuro Extension(最大流)

    Kakuro Extension Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. angular的一些问题

    引入第三方类库 1.安装依赖 npm install jquey --save 2.引入项目 在angular-cli.json "scripts": [ "../nod ...

  5. (转)用python获取页面返回的cookie

    网址如下: crifan:http://www.crifan.com/get_cookie_from_web_response_in_python/ . . . .

  6. 转:RBAC权限控制

    名词解释: RBAC:Role-Based Access Control,基于角色的访问控制   关键词: RBAC,Java Shiro,Spring Security,   一. RBAC 要解决 ...

  7. lucene、solr、nutch三者的关系

    lucene是一个做搜索用的类库. nutch和solr都是基于lucene的,二者都是可直接运行的应用程序: 直接在业务上使用lucene的倒是不太多见. solr主要提供了建立索引(用户可以直接p ...

  8. [NOIp普及组2011]瑞士轮

    洛谷题目链接:瑞士轮 题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较 ...

  9. php连接mysql报错——Fatal error: Call to undefined function mysql_connect() in

    练习php连接mysql数据库 代码:mysql_connect("127.0.0.1:3306","root", ..... 浏览器报错:Fatal erro ...

  10. 谈pkusc2016的几道数学题

    题面搬来的qwq(忘记出处了 水印应该能表示) [题解] 1. 我们看到这题先想到令(x+y+z)^3 展开得到一坨,稍微减减,得到我们要求证 delta = 3xy^2+3xz^2+3yx^2+3y ...