Poj 2349 Arctic Network

【代码超详解】POJ 2349 Arctic Network(Kruskal 算法) 一、题目描述 阅读详情

Arctic Network
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 9557 Accepted: 3187

Description

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

代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<ctime>
#include<stack>
using namespace std; 
double map[505][505];
int dx[505][2];
double ad[255005];
int n, m;

double cl(int x, int y,int k , int l )
{
	double a = x;
	double b = y;
	double c = k;
	double d = l;
	return sqrt((a-c)*(a-c)+(b-d)*(b-d));
}

int prim()
{
	int i, j, k, s = 0;
	double dis[505]={0};
	int vis[505]={0};
	dis[0] = 200000;
	vis[1] = 1;
	for(i=1;i<=m;i++)	dis[i]=map[1][i];
	for(i=1;i<m;i++)
	{
		k = 0;
		for(j=1;j<=m;j++)				
		{
			if(dis[j]<dis[k] && vis[j]==0 && dis[j])	k = j;
		}
		vis[k] = 1;
		ad[s++]=dis[k];
		for(j=1;j<=m;j++)				
		{
			if(vis[j])	continue;
			if((dis[j]>map[k][j] || dis[j]==0 ) && map[k][j] )	dis[j]=map[k][j];
		}
	}
	return s;
}

int main()
{
	int a, b, c, key;
//	freopen("in.txt","r+",stdin);/*如果in.txt不在连接后的exe的目录,需要指定路径如D:\\in.txt*/
//	freopen("out.txt","w+",stdout);/*同上*/
	scanf("%d",&key);
	while(key--)
	{
		memset(map,0,sizeof(map));
		memset(map,0,sizeof(dx));
		memset(map,0,sizeof(ad));
		scanf("%d%d",&n,&m);
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&a,&b);	
			dx[i][0] = a;
			dx[i][1] = b;
		}	

		for(int i=1;i<=m;i++)
		{
			for(int j=i;j<=m;j++)
			{
				map[i][j] = map[j][i] = cl(dx[i][0],dx[i][1],dx[j][0],dx[j][1]);
			}	
		}
		
//		for(int i=1;i<=m;i++)
//		{
//			for(int j=1;j<=m;j++)	printf("%lf ",map[i][j]);
//			printf("\n");
//		}
			
		prim();
		sort(ad,ad+m-1);
		printf("%.2lf\n",ad[m-n-1]);			
	}
//	fclose(stdin);
//	fclose(stdout);
	

	return 0;
}

请选择C++编译器,不要选择G++,这就是为什么你WA的主要原因

论G++与C++的区别


机器学习特征选择-t检验 在特征选择的过程中通过计算检验统计量值,比较特征之间的统计量的大小,并降序排列,选取统计值较高的特征,从而起到去除差别小的特征(此差别小的特征难以区分不同的额类别)的目的。 以t检验(Student's t test)为例: 假设检验 通过比较两类样本的随机变化,通过计算其p值决定是否拒绝零假设,也即是说:通过计算p值,若p值小于某一阈值则认为两个样本具有显著差异,两个样本是不同的,此时拒绝... 阅读详情

相关推荐

基于ESP32-S3与PCM5102的HiFi网络收音机复刻指南:从硬件设计到软件配置

本文提供了一份详细的基于ESP32-S3与PCM5102的HiFi网络收音机复刻指南。内容涵盖从核心硬件选型(如ESP32-S3主控与PCM5102 DAC芯片)、四路独立LDO供电设计,到软件环境配置、固件烧录及常见问题调试的全过程,旨在帮助创客打造一台支持网络电台、本地播放与蓝牙连接的高保真音频播放器。

weixin_30632267的博客 186

最短路问题-最小生成树-通信问题

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 w

weixin_46204099的博客 422

恭喜,恭喜,iMouse爱鼠XP版全面发布测试,苹果手机自动化测试必须

电脑控制苹果手机,免越狱,免签名,自动化测试

qq_41057894的博客 1063

【POJ 2349 --- Arctic Network】prim || kruskal

【POJ 2349 --- Arctic Network】prim || kruskal 题目来源:点击进入【POJ 2349 — Arctic Network】 Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network...

来日浅谈的博客 542

开源项目 ruoyi-sso-oauth2(一)环境配置

Ruoyi若依实现单点登录SSO、oauth2认证

Xiaoweidumpb 9683

保姆级教程:用ROS2 Humble + Gazebo Classic 从零搭建一个能键盘控制的差分AGV模型

本文提供了一份详细的ROS2 Humble与Gazebo Classic教程,指导用户从零开始搭建一个键盘控制的差分AGV模型。内容涵盖环境配置、Xacro文件设计、Gazebo仿真集成以及键盘控制实现,特别针对常见问题提供解决方案,帮助开发者快速掌握ROS2机器人仿真技术。

weixin_30387423的博客 168

POJ 2349 Arctic Network

2016.12.30【题目简述】 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

Forever_MZY 364

Vivado Combinatorial Loop Alert问题 [DRC LUTLP-1]

Vvado综合和布局布线都通过了但是无法生成bit文件,提示Combinatorial Loop Alert,错误如下图。在RTL图中可以看到LUT的输出连接到了输入上,这个就是。在代码中我并未找到导致这种情况发生的地方,如果遇到类似的问题先检查自己的代码是不是存在组合逻辑连接出现了问题,如果没问题再考虑通过设置去解决问题。

伊丽莎白的学习之路 6031

POJ 2349 Arctic Network——最小生成树

问题来源Arctic Network。 Description 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...

anlian523的博客 388

高缺失率时空数据插补实战:从随机森林到扩散模型的性能对比

数据缺失是数据分析与机器学习建模中普遍面临的挑战,尤其在时空数据领域,传感器故障、传输中断等问题常导致数据不完整。数据插补技术旨在基于已知数据的模式和关联性,合理估算缺失值,为后续分析提供可靠基础。其核心原理在于利用数据的时空相关性(如时间周期性、空间邻近性)及与外部驱动因素(如交通、气象)的关联构建预测模型。这项技术的价值在于能将不完整的数据集转化为可用于高质量分析和预测的可用资产,广泛应用于环境监测、交通流量预测、金融风控等领域。本文聚焦于一个极具挑战性的场景——PM2.5监测数据缺失率高达82%,通过

weixin_30363285的博客 544

在MATLAB和Simulink中设计并仿真一个电动汽车整车动力学模型与控制系统

电动汽车(EV, Electric Vehicle)的动力学建模与控制仿真在车辆开发过程中起着至关重要的作用。通过Simulink进行整车动力学模型的构建和控制策略的验证,可以有效评估车辆性能、优化系统设计并降低开发成本。以下是如何在MATLAB和Simulink中设计并仿真一个电动汽车整车动力学模型与控制系统的详细步骤。通过上述步骤,我们成功设计并实现了基于Simulink的电动汽车整车动力学模型与控制仿真。该系统能够模拟复杂的整车动力学行为,验证控制策略的有效性,并通过优化设计提高车辆的性能和可靠性。

xiaoheshang_123的博客 549

POJ-2349题解

POJ-2349 题目描述The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies ar...

cpongo11的博客 518

32、社交媒体大数据中的情感分析与网络欺凌检测

本文探讨了社交媒体大数据在情感分析和网络欺凌检测中的应用。情感分析有助于应对自动化带来的社会变化、促进社会包容和推动环境保护。网络欺凌作为一种严重的在线危害,其检测依赖于数据预处理、特征提取与深度学习模型(如CNN、LSTM)进行分类。文章还总结了大数据在欺诈检测、医疗、制造、交通等领域的广泛应用,并分析了数据存储、处理速度、质量和技术工具等方面的挑战,提出了相应的应对策略。未来,随着技术进步,社交媒体大数据将在更多领域发挥关键作用。

cc789的博客 91

POJ 2349 Arctic Network

POJ 2349 Arctic Network Description The Department of National Defence (DND) wishes to connect several northern outposts by a wireless network. Two different communication technologies are to be used ...

旺崽的博客 3093

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

[POJ 2349] Arctic Network

[题目链接] http://poj.org/problem?id=2349 [算法] 首先,我们发现答案是具有单调性的,所以我们可以二分答案 检验时,我们将所有距离小于二分值的点连边,然后判断联通块数量是否小于等于S即可 [代码] #include <algorithm> #inc...

181

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

poj2349 Arctic Network

题目链接:http://poj.org/problem?id=2349 题意:有s颗星球,有p个雷达站,如果雷达站在同一个星球上,不需要距离就可以直接通信,如果不在一个星球上,他们之间的距离不能超过D,现在给你p个雷达站的坐标,如果要把这整个雷达站连通,问你最小的D是多少 解析:首先要联通全部雷达站,肯定是最小生成树,然后让你求一个D值,雷达站之间连边,相当于如果距离大于D就不能相连,那么可以先

22h's Blog 433

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【POJ】[2349]Arctic Network

理解题意之后也并不算太难 大意是给了一些坐标来求最小生成树 然而让输出的是最大边的值,而因为还有卫星可供通讯 所以只需要当有P个点S个卫星时 共P-1条边里舍去S-1条大的边所以这里我感觉用Kruskal更好一些 而且当取了 P-1-(S-1)==P-S条边时,这一条边便是所要求边 不需要进行后续操作了

BoilTask Talk Show 531

POJ2349 Arctic Network

题目链接:http://poj.org/problem?id=2349 求最小生成树中第S大的边,结点给的是坐标(坑爹啊) #include #include #include #include #include #include using namespace std; #define N 500 struct edge { int u, v; double w;

浅雨歌 515

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: ev...

aocan6909的博客 142

poj 2349 Arctic Network

Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5764 Accepted: 2007 题目链接:http://poj.org/problem?id=2349 Description The Department

优快云515的专栏 1130

POJ-2349-Arctic Network

链接:https://vjudge.net/problem/POJ-2349#author=clzls 题意: 国防部(DND)要用无线网络连接北部几个哨所。两种不同的通信技术被用于建立网络:每一个哨所有一个无线电收发器,一些哨所将有一个卫星频道。 任何两个有卫星信道的哨所可以通过卫星进行通信,而不管他们的位置。同时,当两个哨所之间的距离不超过D时可以通过无线电通讯,D取决于对收发器的功率。...

weixin_33705053的博客 118

poj 2349 Arctic Network

http://poj.org/problem?id=2349 Arctic Network Time Limit:2000MS Memory Limit:65536K Total Submissions:12544 Accepted:4097 Description The Department of Nation...

deyou1988的专栏 134

POJ - 2349 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 net...

GxhZxx的博客 316
上一篇: Ubuntu 字体修改以及字体的相关知识
下一篇: Poj 2528 Mayor's posters
梁千仞
博客等级 码龄15年 12粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值