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 ...
随机推荐
- Omi框架学习之旅 - Hello World 及原理说明
学什么东西都从hello world开始, 我也不知道为啥. 恩,先上demo代码, 然后提出问题, 之后解答问题, 最后源码说明. hello world - demo: class Hello e ...
- Parallel.For 你可能忽视的一个非常实用的重载方法
说起Parallel.For大家都不会陌生,很简单,不就是一个提供并行功能的for循环吗? 或许大家平时使用到的差不多就是其中最简单的那个重载方法,而真实情况 下Parallel.For里面有14个重 ...
- Linux shell-grep
grep --help备忘录 Usage: grep [OPTION]... PATTERN [FILE]...Search for PATTERN in each FILE or standard ...
- 关于binary log那些事——认真码了好长一篇
本文介绍binlog的作用以及几个重要参数的使用方法,同时通过实验来描述binlog内部记录内容:row .statement跟mixed的设置下,记录了哪些东西,最后会简单介绍下binlog ser ...
- Frame框架
框架 frameset 框架集 如果使用框架集,当前页面不能有body cols="300,*" :左右拆分,左边宽300,右边宽剩余 rows=" ...
- python 调取 shell 命令的几种方法
os.system()无法获得到输出和返回值 os.popen()output = os.popen('cat /proc/cpuinfo')print output.read()返回的是 file ...
- React Native 可以走多远?
对于大多数APP开发者来说,能够同时开发出Android APP和IOS APP是不是很牛逼,可是它也不是天方夜谭,自从有了一个叫React Native的东西的出现,这一切就变得可以实现了. 那么到 ...
- XJOI1680阿猫的实验
阿猫的实验 阿猫很喜欢生物学.他还在今年的全国中学生生物学联赛中获得了一等奖.一天,阿猫在实验室听说了这样一种繁殖能力很强的老鼠.这种老鼠在出生后的第一个月,可以生出a 对老鼠:第二个月,可以生出b ...
- 【Egret】使用VSCode 编译,断点调试Egret项目
经过我日积月累的摸索,还是一直模模糊糊的,搞不懂,今天经晨哥点拨两下,一下子就恍然大悟,搞定了怎么弄这个东西,现将经验分享如下. 一.效果目的 1.在VSCode里,直接F5打开Egret页面,并且可 ...
- async/await的多线程问题
今天尝试把.net4.5新增的异步编程模型async/await加入自己的框架,因为从第一印象看,使用async/await的写法实在太方便了,以同步代码的方式写异步流程,写起来更顺畅,不容易打断思路 ...