poj2349,最小生成树!
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
Output
Sample Input
1
2 4
0 100
0 300
0 600
150 750
Sample Output
212.13
题目看起来简单,花了一个多小时才改对,主要是s的问题没有解决!!
用一个数组保存,然后sort一下,求num-s就行了
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const double inf=1e20;
double d[600],cost[600][600],ans[600];
int n,s;
struct node{
double x,y;
}e[600];
double dis(node a,node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void prim()
{
bool vis[600];
for(int i=0;i<=n;i++)
{
vis[i]=0;
d[i]=inf;
}
d[0]=0;
int num=0;
while(1){
int v=-1;
for(int i=0;i<n;i++)
{
if(!vis[i]&&(v==-1||d[i]<d[v]))
v=i;
}
if(v==-1)break;
ans[num++]=d[v];
vis[v]=1;
for(int i=0;i<n;i++)
{
d[i]=min(d[i],cost[i][v]);
}
}
sort(ans,ans+num);
printf("%.2f\n",ans[num-s]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&s,&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&e[i].x,&e[i].y);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
cost[i][j]=cost[j][i]=dis(e[i],e[j]);
}
cost[i][i]=0;
}
prim();
}
return 0;
}
poj2349,最小生成树!的更多相关文章
- [Poj2349]Arctic Network(二分,最小生成树)
[Poj2349]Arctic Network Description 国防部(DND)要用无线网络连接北部几个哨所.两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫 ...
- POJ-2349(kruskal算法+最小生成树中最大边的长度)
Arctic POJ-2349 这题是最小生成树的变形题目.题目的意思是已经有s个卫星频道,这几个卫星频道可以构成一部分的网络,而且不用费用,剩下的需要靠d的卫星接收器.题目要求的就是最小生成树中,最 ...
- [poj2349]Arctic Network(最小生成树+贪心)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17758 Accepted: 5646 D ...
- POJ2349:Arctic Network(二分+最小生成树)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 28311 Accepted: 8570 题 ...
- poj2349 Arctic Network - 最小生成树
2017-08-04 16:19:13 writer:pprp 题意如下: Description The Department of National Defence (DND) wishes to ...
- POJ-2349 Arctic Network(最小生成树+减免路径)
http://poj.org/problem?id=2349 Description The Department of National Defence (DND) wishes to connec ...
- 最小生成树练习3(普里姆算法Prim)
风萧萧兮易水寒,壮士要去敲代码.本女子开学后再敲了.. poj1258 Agri-Net(最小生成树)水题. #include<cstdio> #include<cstring> ...
- POJ-2349 Arctic Network---MST的第m长的边
题目链接: https://vjudge.net/problem/POJ-2349 题目大意: 要在n个节点之间建立通信网络,其中m个节点可以用卫星直接连接,剩下的节点都要用线路连接,求剩下这些线路中 ...
- kuangbin最小生成树专题
网址:https://vjudge.net/contest/66965#overview 第一题: poj1251 裸最小生成树 #include<iostream> #include&l ...
随机推荐
- spdlog源码阅读 (2): sinks的创建和使用
2. sink创建 2.1 还是rotating_file_sink 我们仍然以rotating_file_sink为例来说明在spdlog中sink的创建过程. 在spdlog-master/tes ...
- raise RuntimeError("autoconf error") RuntimeError: autoconf error
pip 安装模块时遇到下错误,没有粘贴全,差不多都是这样.这个情况是 pip 安装模块 需要 gcc 及 python-devle 支持, ubuntu 是 python-dev ,使用Yum 安装即 ...
- HANA CDS与ABAP CDS
如果你在网络或者SCN上面搜索CDS,即SAP的Core Data Services,你会很容易地找到类似“Core Data Services(CDS)是一个在SAP HANA中用于定义和消费富语义 ...
- 关于CO中的processRequest和processFormRequest的区别
在OAF开发中会有许多的CO,而一般情况下CO中的有两个基本的方法那就是processRequest和processFormRequest,processRequest是页面执行初始化的时候执行的方法 ...
- js的搜索遍历精讲
搜索算法应该算是每种算法的重点与难点了,本文将讲解JavaScript中的各种常用的遍历算法:希望对大家有所帮助. 深度优先遍历顺序:1245367 广度优先遍历:1234567 1.深度优 ...
- 老李分享:Android性能优化之内存泄漏2
这种创建Handler的方式会造成内存泄漏,由于mHandler是Handler的非静态匿名内部类的实例,所以它持有外部类Activity的引用,我们知道消息队列是在一个Looper线程中不断轮询处理 ...
- 性能调优之Java系统级性能监控及优化
性能调优之Java系统级性能监控及优化 对于性能调优而言,通常我们需要经过以下三个步骤:1,性能监控:2,性能剖析:3,性能调优 性能调优:通过分析影响Application性能问题根源,进行优化 ...
- 各位Coder看过来
为了丰富博客内容,也为了解决一些实际的问题,现准备出一系列博文,内容为各位回复评论指明需要的知识点,将在近期为你解决并提供还算精要的讲解:评论内容要求 Coder:+需要的技术内容.技术内容不限领域, ...
- Xmpp实现简单聊天系列 --- ①openfire部署
1. 下载最新的openfire安装文件 官方下载站点:http://www.igniterealtime.org/downloads/index.jsp#openfire 2. 下载完成后,执行你的 ...
- BootstrapBootbox居中
/* 模态框居中样式 */ .bootbox-container { position: fixed; ; ; ; ; ; overflow-y: auto; } .bootbox-container ...