由于在上一篇文章用了大量的文字已经对于最小生成树的两种算法(克鲁斯卡尔和普利姆算法)做了基础的讲解,下面的话我就大概说一下思想和解题步骤,然后再在附加上一个昨天做题(虽然说很基础但是对于初学的我就有点……)的一个题解;
最小生成树第一次讲述的连接:https://blog.csdn.net/weixin_44606952/article/details/99301454
克鲁斯卡尔算法:
就是把各条路径的距离先进行简单的排序(从小到大),我们的目的是找到最短长度把所有的城市都连通起来,说明白点就是求所有路径之间的总和,有n个顶点我们就需要n-1条线路把这几个点连接起来,连接的思想很简单,遍历每一条边,要是没有在建成的树上的话,就把这一条边加上(因为已经排过序所以它一定是当前的最短路)当找到n-1条边的时候就结束,代表已经找够了;用到的算法有:快排,并查集上一篇文章里面有相关的连接不懂的可以去看看:
普里姆算法 :
先把所有点到1号点的距离存入dis数组,在后续的过程中依然使用最短路径的思想将dis数组中的数据做出改变,不过数组中的值代表的含义有发生改变他表示的是当前节点和连着他的上一个节点的距离遍历完所有节点就结束
Arctic Network讲解:
原文:
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

题意:
有一些前线站点是通过无线通信(传达信号与收发器的功率有关)来互相传信息的,有些是通过卫星的卫星可以不受距离的限制,但是无线就不行了,现在给出建立卫星的前哨站数目,和所有的前哨站数问需要的收发器能满足使用的当前收发器最小功率的距离应该是多少
解题思路:
先用普利姆算出各个点之间的距离存入dis数组,对于数组进行排序,排好之后用m-1条边减去用无线电信号连接的那一条边剩下的最大边就是要找的距离D了也就是输出dis[m-n+1]
ACa代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
double e[2000][2000];
double dis[20000];
int book[20000];
int inf=99999999;
struct node{double x;double y;
}s[2000];
int main()
{int n,m,t;scanf("%d", &t);while(t--){scanf("%d %d", &n,&m);double min, sum=0;for(int i=1; i<=m; i++)scanf("%lf %lf", &s[i].x,&s[i].y);for(int i=1; i<=m; i++)for(int j=1; j<=m; j++)e[i][j]=e[j][i]=sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y));for(int i=1; i<=m; i++)dis[i]=e[1][i];memset(book,0,sizeof(book));int count=0,j;count++; book[1]=1;while(count<m){min=inf;for(int i=1; i<=m; i++){if(book[i]==0&&dis[i]<min){min=dis[i]; j=i;}}book[j]=1;count++;for(int k=1; k<=m; k++){if(book[k]==0&&dis[k]>e[j][k])dis[k]=e[j][k];}}double p;//排序for(int i=1; i<m; i++){for(int j=i+1; j<=m; j++){if(dis[i]>=dis[j]){p=dis[i]; dis[i]=dis[j];dis[j]=p;}}}printf("%.2f\n", dis[m-n+1]);}return 0;
}

Arctic Network题解+(最小生成树二次理解 )相关推荐

  1. TYUT-A专题题解(二)

    TYUT-A专题题解(一) TYUT-A专题题解(二) 36暴力枚举 AOJ0008 Sum of 4 Integers[暴力]_海岛Blog-CSDN博客 HDU1407 测试你是否和LTC水平一样 ...

  2. Transformer(二)--论文理解:transformer 结构详解

    转载请注明出处:https://blog.csdn.net/nocml/article/details/110920221 本系列传送门: Transformer(一)–论文翻译:Attention ...

  3. #1098 : 最小生成树二·Kruscal算法

    #1098 : 最小生成树二·Kruscal算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 随着小Hi拥有城市数目的增加,在之间所使用的Prim算法已经无法继续使用 ...

  4. hihoCoder-1098最小生成树二·Kruscal算法 (最小生成树)

    最小生成树二·Kruscal算法 描述 随着小Hi拥有城市数目的增加,在之间所使用的Prim算法已经无法继续使用了--但是幸运的是,经过计算机的分析,小Hi已经筛选出了一些比较适合建造道路的路线,这个 ...

  5. 关于一些初级ACM竞赛题目的分析和题解(二)。

    关于一些初级ACM竞赛题目的分析和题解(二). 今天写了关于排序的题  中间有加号的复杂的一行字符   其次还有关于tolower函数的应用, 上题                           ...

  6. poj2349:Arctic Network(最小生成树)

    总时间限制:  2000ms  内存限制:  65536kB 描述 The Department of National Defence (DND) wishes to connect several ...

  7. 【POJ - 2349】【UVA - 10369】 Arctic Network(最小生成树求权值第k大的边)(内附两种算法)

    题干: The Department of National Defence (DND) wishes to connect several northern outposts by a wirele ...

  8. Arctic Network UVA - 10369 (最小生成树,适合prim)

    给出n个点将他们连成最小生成树,给出k个卫星,有了这些卫星就可以无代价地连接一些边.求出在此条件下的最长的边 也就是求出最小生成树的第k小条边 考虑到这个图的边比较多,选择使用prim算法,需要注意的 ...

  9. #2020.02.05训练题解#最小生成树入门(F题)

    题源CF-1108 CF-1108-MST Unification Description You are given an undirected weighted connected graph w ...

最新文章

  1. windows下pycharm连接vagrant的python环境
  2. 数据库---查询(详细)
  3. NET Core微服务之路:SkyWalking+SkyApm-dotnet分布式链路追踪系统的分享
  4. 正则 指定开头结尾_Python核心知识系列:正则表达式与JSON
  5. bzoj4415 [Shoi2013]发牌 线段树
  6. 单片机毕业设计 超声波雷达可视化系统
  7. Xilinx IP核 之DDS
  8. 计算机网络——大数据、物联网
  9. 在利用DXP2004软件进行PCB设计时——自制元器件封装如何添加网络(布线问题)
  10. Docker端口映射实现网络访问
  11. 2022前端未来发展趋势
  12. OI生涯回忆录(Part8:至高一省选Day1)
  13. 20162327WJH Android开发程序设计实验报告
  14. Beijing Thwarts Coke's Takeover Bid
  15. 也许你需要看看这篇文章
  16. GO语言Comma-ok断言
  17. c# winform 支付宝付款
  18. stm32 iic 从机模式 时钟低电平问题
  19. SPI Flash/Nor Flash/Nand Flash
  20. 跟着彭亮一起学人工智能之深度学习--零基础学人工智能

热门文章

  1. Java属性setProperty()方法与示例
  2. Linux使用snoopy记录命令执行日志
  3. 编程需要学计算机基础嘛,非计算机专业学编程需要什么基础?
  4. 什么是专利恢复费和滞纳金,怎么区分?
  5. python中email模块的一些用法
  6. JavaCV的摄像头实战之四:抓图
  7. 毕昇配置pytorch
  8. 2018天猫双11各项数据发布
  9. 详解 三种蓝牙协议栈方案
  10. 不要再用 C/C++ 的这种说法了!