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++的区别


5分钟搞懂异构图注意力网络(HAN):从元路径到节点聚合的全流程解析 本文深入解析异构图注意力网络(HAN)的核心原理与实战应用,从元路径设计到多级注意力实现的全流程。HAN通过节点级和语义级双重注意力机制,有效处理包含多种节点和边类型的异构图数据,在电商推荐、学术网络分析等场景展现卓越性能。文章提供DGL实现代码和调参技巧,帮助开发者快速掌握这一强大工具。 阅读详情

相关推荐

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

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

计组实验5:cache大小测量与 cache line 大小测量

前言 今天做了实验5,通过 c 语言测 cache 参数。其实按理来说挺简单的,只是我们班没给代码,纯靠自己。听说别的班有给代码 emm 因为《深入理解计算机系统》这本书上面给的代码是 Linux 平台下的,而且需要一个 fcyc2 头文件,可以在 https://github.com/fabiensanglard/CpuCacheMountainViewer 这里找到。 ⚠ 我没有在 Linux 下试过课本上面的代码。。。 我是在 win10 下测试的。。。 所以 。。。 我并不确定我的代码是否正确。

AKGWSB 's blog 1万+

【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

从Gotham到Foundry:拆解Palantir三大产品线,看它如何用‘本体’统一企业数据与AI

本文深入解析Palantir的三大产品线Gotham、Foundry和Apollo,揭示其如何通过独特的'本体'架构实现企业数据与AI的无缝融合。从国防情报到商业决策,Palantir的产品架构展现了强大的数据整合与AI赋能能力,为企业构建数字孪生提供革命性解决方案。

weixin_30823001的博客 321

张量分解浅谈(四 Tucker 分解)

学完了SVD算法之后,我们继续回到张量几大分解的学习上来,本期学习的主要内容是张量的 Tucker 分解 以及 前面的CP分解还留下一点没有说完,正好一并补齐!后面的公式我将采用颜色标记,红色代表必须掌握,蓝色尽量掌握! 在这之前先附一张图,包含了各种运算符号的名称含义,大部分是前面说过或者使用过的: Tensor decomposition一 . Tucker 分解公式介绍和原理二 . 张量的 n-Rank 一 . Tucker 分解公式介绍和原理 我们先来看一张被使用过很多次的Trucker 分解图

欢迎来到 豪哥 的博客 1万+

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

利用ArcGIS的模型构建器实现批量投影栅格和批量克里金插值

博主要批量投影几百个栅格,但是ArcGIS中的投影栅格的批处理工具需要手动一条条设置参数,还是麻烦,因此学习了使用模型构建器(ModelBuilder)来批量投影栅格,可以导入需投影栅格的文件夹,然后迭代投影,并按栅格原名逐个输出到指定目录。 1.在工具箱里构建模型 在arctool box里右键点击空白处,选择【添加工具箱】,点击ArcGIS默认工作目录的工具箱进行添加,然后Toolbox就会被添加到ArcToolbox页面,右键点击Toolbox,选择“新建”-“模型” 2.编写模型 (1).

qq_36958801的博客 1万+

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

小红书UID泄露风险揭秘:如何防止你的手机号被社工库关联(附防护指南)

本文揭示了小红书UID泄露的严重风险,详细解析了UID与手机号关联后被社工库利用的完整链条。通过分析黑产的数据整合技术,提供从基础到进阶的防护策略,包括密码管理、账号隔离和应急响应措施,帮助用户有效防范个人信息泄露风险。

ol789012345的博客 1510

Python对象的基本组成和内存示意图及引用的本质

在Python中,变量也称为:对象的引用(reference)。变量存储的就是对象的地址。变量不需要显式声明类型。根据变量引用的对象,Python解释器自动确定数据类型。一个内存块,拥有特定的值,支持特定类型的相关操作。变量位于:栈内存(压栈出栈等细节,后续再介绍)。⚠️Python是动态类型语言。变量通过地址引用了“对象”。

Calor13的博客 557

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

CANoe如何实现TLS协议

TLS,Transport Layer Security,传输层安全协议。是在传输层和应用层之间,为了保证应用层数据能够安全可靠地通过传输层传输且不会泄露的安全防护。

jasonj333 1159

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

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

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

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

[POJ 2349] Arctic Network

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

181

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

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

poj2349 Arctic Network

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

22h's Blog 433

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

【POJ】[2349]Arctic Network

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

BoilTask Talk Show 532

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;

浅雨歌 516

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、付费专栏及课程。

余额充值