POJ 2349:Arctic Network【2019北大推免G】

无线网络建设与最短路径算法
本文介绍了一个关于国防部门在北极地区建立无线网络的问题。网络需要通过无线电和卫星通信技术连接各个哨所,其中至少需要S个卫星通道确保任意两个哨所间有通信路径。题目给出坐标信息,要求确定最小的无线电通信范围D,使得所有哨所能相互连接。解决方案是使用并查集结合最小生成树算法,找到满足条件的最小D值。文章涉及图论、算法和网络通信技术。

2349:Arctic Network【2019推免G】

  • 查看

  • 提交

  • 统计

  • 提示

  • 提问

  • 总时间限制:

    2000ms

  • 内存限制:

    65536kB

  • 描述

    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.

  • 输入

    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).

  • 输出

    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.

  • 样例输入

    1
    2 4
    0 100
    0 300
    0 600
    150 750
    
  • 样例输出

    212.13
    

题解

  • 从距离最短的边开始连接(并查集),直到集合数目<=S(此时每个集合一个基站,从而可以连通)

    • 由于S>=1则这个条件是成立的

    • 实际上:S=0时,结束条件:集合数目<=1(这是S+1);S>0时,结束条件:集合数目<=S(另外,注意到S=1的情况其实基站就没用了hhh)

    • 存在距离相等的边的情况,在选定某个距离的时候可能新增连接多条边,所以for循环里面写个while,但是集合数目只要减少到了S就可以结束(考虑后面还没有连接到、但是距离==D实际上是新增边的边,连接它们只是让集合数目更小,所以是可以结束的,直接for循环是可以的)

  • 时间复杂度:最小生成树中边的数目为P-1,因此最多连接O§条边 S < P <= 500;每连接一条边,找root(同时使用路径压缩和启发式合并),O(a§)近似于O§。所以大概P2=105

  • 数据范围:距离:坐标 0 and 10,000,因此|X1-X2|2最大为(104)2=108,距离的平方可以用int型

  • 注意:多组数据,全局变量注意清空状态!

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值