Arctic Network( POJ - 2349)

简介: Arctic Network( POJ - 2349)

题目:

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

最小生成树prime模板题目,不过题目中给出有的距离可以用卫星通信,所以把每一个最短权值求出来,然后从大到小排序,取第m个权值为最大权值。

程序代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
struct node
{
  int x;
  int y;
}q[50000];
int e[2000][2000],dis[5000],book[5000];
double a[5000];
int main()
{
  int n,m,i,j,k,min,t1,t2,t3;
  int inf=99999999;
  int count,sum;
  int N;
  double tem;
  scanf("%d",&N);
  while(N--)
  {
    count=0;
    memset(dis,0,sizeof(dis));
    memset(book,0,sizeof(book));
    memset(a,0,sizeof(a));
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
      scanf("%d%d",&q[i].x,&q[i].y);
    for(i=1;i<=m;i++)
      for(j=1;j<=m;j++)
        if(i==j)  e[i][j]=0;
        else    e[i][j]=inf;
    for(i=1;i<m;i++)
      for(j=i+1;j<=m;j++)
        e[i][j]=e[j][i]=(q[i].x-q[j].x)*(q[i].x-q[j].x)+(q[i].y-q[j].y)*(q[i].y-q[j].y);
    for(i=1;i<=m;i++)
      dis[i]=e[1][i];
    book[1]=1;
    count++;
    while(count<m)
    {
      min=inf;
      for(i=1;i<=m;i++)
      {
        if(book[i]==0&&dis[i]<min)
        {
          min=dis[i];
          j=i;
        }
      }
      book[j]=1;
      a[count]=sqrt(dis[j]);
      count++;
      for(k=1;k<=m;k++)
      {
        if(book[k]==0&&dis[k]>e[j][k])
          dis[k]=e[j][k];
      }
    }
    for(i=1;i<m;i++)//把权值从大到小排序
      for(j=i+1;j<m;j++)
      {
        if(a[i]<a[j])
        {
          tem=a[i];
          a[i]=a[j];
          a[j]=tem;
        }
      }
    printf("%.2f\n",a[n]);
  }
  return 0; 
} 

相关文章
|
缓存 Java API
JVM 四种引用和使用场景
在JDK 1.2之后,Java对引用的概念进行了扩充,将引用分为强引用(Strong Reference)、软引用(Soft Reference)、弱引用(Weak Reference)、虚引用(Phantom Reference)四种,Java 4种引用的级别由高到低依次为:强引用 > 软引用 > 弱引用 > 虚引用。
544 0
|
9月前
|
编解码 关系型数据库 Java
阿里云服务器4核8G最低价格:通用算力型、经济型、计算型等不同实例活动价格参考
阿里云4核8G云服务器是企业级应用、高流量网站及复杂开发测试环境的优选配置。本文解析了通用算力型u2a实例、通用算力型u2i实例、经济型e实例、计算型c9i实例四款主流产品,它们最低活动价分别为898.20元/年、1252.63元/年、1595.11元/年、3147.56元/年起。各实例在性能、架构及适用场景上各有侧重,用户可根据需求与预算选择,并建议购买前领取优惠券以获取额外减免。
|
9月前
|
机器学习/深度学习 数据采集 人工智能
直升机停机坪目标检测数据集(9000 张图片已划分、已标注)| AI训练适用于目标检测任务
本数据集含9000张高质量标注图像,覆盖机场、医院楼顶、港口等多场景,支持YOLO/Faster R-CNN等模型;已划分train/val/test,单类“Helipad”,具多尺度、多角度、多光照特性,适用于无人机降落、低空导航与遥感检测。
|
人工智能 运维 安全
从“裸奔”到“金钟罩”:AI身份凭据安全的进化之路
构建身份权限安全,护航企业数据合规
2286 37
|
缓存 自然语言处理 API
阿里云百炼产品月刊【2025年8月】
阿里云百炼平台8月推出多项更新与活动。通义千问系列重磅升级,新增多款图像、语音及研究模型,如Qwen-Image、Qwen-Image-Edit、Qwen-MT-Image、Wan2.2-S2V等,全面增强图文生成与编辑能力。推出Qwen-Flash轻量模型,优化代码与推理性能,支持高并发低延迟场景。平台服务稳定性提升,部分模型计费策略调整,上下文缓存价格降低至input_token的20%,并提供100万免费token额度。同步上线“实训Agent创客”活动,助力用户快速上手新模型,提升实践能力。
1361 0
|
9月前
|
安全 Java 测试技术
Java 工程化体系:代码规范与团队协作全链路标准
本文系统阐述Java工程化规范体系,涵盖代码命名、格式、异常处理、日志、注释、模块结构、Git流程、自动化门禁等七大维度,强调规范是团队协作的“通用语言”,须通过工具链强制落地,而非依赖人工自觉,最终实现高质量、可持续的研发交付。
720 1
|
12月前
|
SQL Oracle 关系型数据库
Oracle 数据塑形:行列转换与集合运算
报表要求的数据格式总是千奇百怪?其实用SQL就能让数据轻松“变形”。想把多行内容(比如各科成绩)合并成一行里的多列,可以用经典的CASE WHEN,或者在11g以上版本里用更简洁的PIVOT。反过来,把宽表拆成多行,也有UNION ALL和更方便的UNPIVOT。学会这些,再配合UNION、INTERSECT等集合运算,数据就能随心所欲地展示了。
1049 14
|
12月前
|
数据采集 缓存 网络协议
医疗设备协议对接开发
医疗设备协议对接需实现监护仪、呼吸机等与HIS、EMR等系统间的数据互通,涵盖HL7、DICOM、ASTM等标准及私有协议解析。开发流程包括需求分析、解析开发、数据清洗、网关构建与闭环验证,强调时序性、完整性与安全性。推荐使用Java/Go语言,结合Mirth、Wireshark等工具提升效率。#医疗信息化 #协议对接
|
机器学习/深度学习 算法 Python
BP神经网络算法讲解及实战应用(超详细 附源码)
BP神经网络算法讲解及实战应用(超详细 附源码)
3507 0
|
存储 开发框架 .NET
ASP.NET Core SignalR系列之Hub教程
ASP.NET Core SignalR系列之Hub教程
712 0