poj 2349 Arctic Network

news/2024/7/10 6:12:13 标签: distance, network, output, ini, each, pair

Arctic Network

Time Limit: 2000MS

Memory Limit: 65536K

Total Submissions: 5764

Accepted: 2007

题目链接:http://poj.org/problem?id=2349

Description

The Department of NationalDefence (DND) wishes to connect several northern outposts by a wirelessnetwork. Two different communication technologies are to be used inestablishing the network: every outpost will have a radio transceiver and someoutposts 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 radioonly if the distance between them does not exceed D, which depends of the powerof the transceivers. Higher power yields higher D but costs more. Due topurchasing and maintenance considerations, the transceivers at the outpostsmust be identical; that is, the value of D is the same for every pair ofoutposts.

Your job is to determine the minimum D required for the transceivers. Theremust be at least one communication path (direct or indirect) between every pairof outposts.

Input

The first line of inputcontains N, the number of test cases. The first line of each test case contains1 <= S <= 100, the number of satellite channels, and S < P <= 500,the number of outposts. P lines follow, giving the (x,y) coordinates of eachoutpost in km (coordinates are integers between 0 and 10,000).

Output

For each case, output shouldconsist 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

Source

Waterloolocal 2002.09.28

 

题意:

         m个坐标点,没两个点之间通信,如果某两个点有卫星频道,,那么这两个点可以无限距离通信,如果没有,那么只能在一定范围D内通信,问D的最大值是多少

解题思路:

         m各坐标点抽象成一张完全图图,再用prim算法计算其最小生成树,记录最小生成树每条边的权值,在对边进行从大到小排序,在取该数组中的n个值即可

 

代码:

#include <iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAX 1003
#define VALUE 999999999
using namespace std;


struct distinct
{
    int x;
    int y;
};

double g[MAX][MAX];
double minCost[MAX];
int visited[MAX];
double arr[MAX];
//求两点之间的距离
double dis(int x1,int y1,int x2,int y2)
{
    return sqrt((x2-x1)*(x2-x1)*1.0+(y2-y1)*(y2-y1)*1.0);
}

//求最小生成树
void prim(int n)
{
    int i;
	int temp=0;
    for(i=0;i<n;i++)
    {
        visited[i]=0;
        minCost[i]=g[0][i];
		arr[i]=0;
    }
    minCost[0]=0;
    while(true)
    {
        int t=-1;
        for(i=0;i<n;i++)
        {
            if(visited[i]==0 && (t==-1 || minCost[i]<minCost[t]))
            {
                t=i;
            }
        }
        if(t==-1)
            break;
        visited[t]=1;
		arr[temp]=minCost[t];//保存每一条最短路径
		temp++;
        //printf("%d\t",minCost[t]);
        for(i=0;i<n;i++)
        {
            if(minCost[i]>g[i][t] && g[i][t]!=0)
            {
                minCost[i]=g[i][t];
            }
        }
    }
}

bool cmp(double i,double j)    //比较函数。
{
	return i>j;
}


int main()
{
    int ts;
    int i,j;
    scanf("%d",&ts);
    while(ts--)
    {
        memset(g,0,sizeof(g));
        int n,m;
        distinct d[MAX];
        memset(d,0,sizeof(d));
        scanf("%d%d",&n,&m);
        for(i=0;i<m;i++)
        {
            scanf("%d%d",&d[i].x,&d[i].y);
            for(j=0;j<i;j++)
            {//建立无向完全图
                g[i][j]=dis(d[i].x,d[i].y,d[j].x,d[j].y);
                g[j][i]=g[i][j];
            }
        }
       prim(m);

	   //对数组minCost进行从大到小排序
	   sort(arr,arr+m,cmp);



	   if(n==0)
	   {
	       printf("%.2lf\n",arr[0]);
	   }
	   else
		   printf("%.2lf\n",arr[n-1]);
    }
    return 0;
}


 


http://www.niftyadmin.cn/n/862580.html

相关文章

2022.04.11【读书笔记】|单细胞转录组概述

文章目录摘要研究意义转录组学意义技术比较研究方法细胞筛选文库构建测序实验方法实验流程常见问题分析内容&#xff08;重点&#xff09;分析内容总览细胞亚群分类细胞类型频率统计Marker基因分析富集分析样本差异分析逆时分析WGCNA细胞通讯分析转录因子分析总结摘要 本篇笔记…

2022.04.13【读书笔记】|10X单细胞转录组分析流程介绍

文章目录摘要课程目录流程分析软件基础分析流程数据质控测序统计细胞过滤表达定量聚类分群数据合并批次效应MNN矫正CCA矫正harmony矫正细胞过滤亚群聚类高变基因筛选与PCA分析聚类可视化亚群鉴定(关键&#xff0c;耗时最久)标记基因亚群定义特征分析频率统计亚群特征表达基因个…

M2Eclipse:Maven Eclipse插件无法搜索远程库的解决方法

使用Eclipse安装了maven插件之后&#xff0c;创建Maven工程&#xff0c;发现添加依赖“Add Dependency”的时候无法自动搜索远程库。 如果不能搜索远程库那用这个插件有啥用撒。。。 查遍了所有的maven配置文件都没发现问题。 最后发现是插件本身的问题。原因是远程库的索引没有…

2022.04.14【读书笔记】|WGCNA分析原理和数据挖掘技巧

文章目录背景RNA-seq分析一般逻辑局限性基因表达和调控方式与网络相关的基础概念无尺度网络模块以及模块特征值连通性非权重网络权重网络核心基因WGCNA网络原理和构建过程简介哲学理念网络构建的两个核心步骤基因的过滤去除低丰度的基因去除没有变化的基因最终期望&#xff1a;…

2022.04.14【读书笔记】|转录因子分析

文章目录背景介绍定义作用方式转录因子特点算法原理共表达网络&#xff08;GENIE3&#xff09;Motif 富集&#xff08;Ris-Target&#xff09;活性定量&#xff08;AUCell&#xff09;结果查看应用思路背景介绍 定义 转录因子&#xff08;transcription factors, TFs&#xf…

STL文档

STL文档 1 List 2 头文件:#include<list> 3 实例化&#xff1a;list<类型>ListName 4 原型&#xff1a;namespacestd { template <class T, class Allocator allocator<T> > classlist; } 构造函数(使得可以在定义时赋初值)…

C++实现Composite模式

由于CSDN目前图片不能显示&#xff0c;本文暂时发表在&#xff1a; http://patmusing.blog.163.com/blog/static/135834960201002321018760/

2022.04.15【单细胞】|Seurat安装,C++ compiler supports the long long type... no解决方法

文章目录项目场景问题描述原因分析解决方案总结项目场景 最近学习单细胞转录组&#xff08;scRNA&#xff09;分析&#xff0c;这个分析需要提前安装R4.0还有Seurat等R包进行分析&#xff0c;同事在创建新环境后正常情况下都可以顺利安装&#xff0c;然而到我这边&#xff0c;…