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 ...
随机推荐
- css基础学习---简单理解
1:在css中定义图片相对路径 #primary-nav { //相对路径 background: url(../images/alert-overlay.png) repeat-x; height: ...
- php学习测试题目
<?php header("content-type:text/html;charset=utf-8"); /* 1.银行给客户每天万分之四的利率,本金10 ...
- Internet Information Services安装与启动
Internet Information Services安装 1.打开控制面板——程序——启动或关闭windows功能 2.找到Internet Information Services ——将其全 ...
- 菜鸟Scrum敏捷实践系列(三)用户故事的组织---功能架构的规划
菜鸟Scrum敏捷实践系列索引 菜鸟Scrum敏捷实践系列(一)用户故事概念 菜鸟Scrum敏捷实践系列(二)用户故事验收 菜鸟Scrum敏捷实践系列(三)用户故事的组织---功能架构的规划 采用Sc ...
- 任何一款IDE的设计思路
我们以Windows操作系统为例.现在,基于操作系统的任何计算机语言,我们说都是高级语言,从C开始.无论是哪一种,都是通过操作系统的API与计算机交互.即便.Net的FrameWork库从一定意义上何 ...
- mybatis的学习笔记
前几天学习了mybatis,今天来复习一下它的内容. mybatis是一个基于Java的持久层框架,那就涉及到数据库的操作.首先来提出第一个问题:java有jdbc连接数据库,我们为什么还要使用框架呢 ...
- ThinkPHP3.2.3版本验证码异步第二次验证时失败的问题解决
最近在用TP3.2.3做一个小项目,纠结于验证码验证问题,重点在于二次验证,举个例子就是常见的登录页面上有个验证码输入框,当用户输入验证码并且鼠标点击在这个输入框之外时候,触发onblur事件,然后a ...
- moment倒计时插件
https://github.com/icambron/moment-countdown
- Swing入门
厌倦了在控制台使用键盘输入并显示结果的过程?是的,在你现在这台电脑上,已经很少有程序使用这种交互方式.本实验将带你初步进入图形用户界面(GUI)的世界,让你学会如何编写屏幕上那些具有特定大小和位置的窗 ...
- 手机自动化测试:Appium源码分析之跟踪代码分析五
手机自动化测试:Appium源码分析之跟踪代码分析五 手机自动化测试是未来很重要的测试技术,作为一名测试人员应该熟练掌握,POPTEST举行手机自动化测试的课程,希望可以训练出优秀的手机测试开发工 ...