UVa 216 Getting in Line (全排列&枚举)

在WPS/Office中免费使用AI,快速提升办公效率!​ 《免费解锁WPS/Office AI办公神器教程》摘要: 本教程详解如何通过第三方插件OfficeAI免费实现WPS/Office智能办公,突破官方付费限制。从安全设置到安装配置,手把手教学,涵盖文档生成、PPT美化、Excel图表等核心功能。关键优势包括零成本、全场景支持及云端/本地双模式切换,并附常见问题解决方案。注意需使用WPS 2024+版本,安装时需临时关闭杀毒软件。教程强调工具来源合法性,建议商用购买正版授权。(149字) 阅读详情

216 - Getting in Line

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=152

Computer networking requires that the computers in the network be linked.

This problem considers a ``linear" network in which the computers are chained together so that each is connected to exactly two others except for the two computers on the ends of the chain which are connected to only one other computer. A picture is shown below. Here the computers are the black dots and their locations in the network are identified by planar coordinates (relative to a coordinate system not shown in the picture).

Distances between linked computers in the network are shown in feet.

For various reasons it is desirable to minimize the length of cable used.

Your problem is to determine how the computers should be connected into such a chain to minimize the total amount of cable needed. In the installation being constructed, the cabling will run beneath the floor, so the amount of cable used to join 2 adjacent computers on the network will be equal to the distance between the computers plus 16 additional feet of cable to connect from the floor to the computers and provide some slack for ease of installation.

The picture below shows the optimal way of connecting the computers shown above, and the total length of cable required for this configuration is (4+16)+ (5+16) + (5.83+16) + (11.18+16) = 90.01 feet.

Input

The input file will consist of a series of data sets. Each data set will begin with a line consisting of a single number indicating the number of computers in a network. Each network has at least 2 and at most 8 computers. A value of 0 for the number of computers indicates the end of input.

After the initial line in a data set specifying the number of computers in a network, each additional line in the data set will give the coordinates of a computer in the network. These coordinates will be integers in the range 0 to 150. No two computers are at identical locations and each computer will be listed once.

Output

The output for each network should include a line which tells the number of the network (as determined by its position in the input data), and one line for each length of cable to be cut to connect each adjacent pair of computers in the network. The final line should be a sentence indicating the total amount of cable used.

In listing the lengths of cable to be cut, traverse the network from one end to the other. (It makes no difference at which end you start.) Use a format similar to the one shown in the sample output, with a line of asterisks separating output for different networks and with distances in feet printed to 2 decimal places.

Sample Input

6
5 19
55 28
38 101
28 62
111 84
43 116
5
11 27
84 99
142 81
88 30
95 38
3
132 73
49 86
72 111
0

Sample Output

**********************************************************
Network #1
Cable requirement to connect (5,19) to (55,28) is 66.80 feet.
Cable requirement to connect (55,28) to (28,62) is 59.42 feet.
Cable requirement to connect (28,62) to (38,101) is 56.26 feet.
Cable requirement to connect (38,101) to (43,116) is 31.81 feet.
Cable requirement to connect (43,116) to (111,84) is 91.15 feet.
Number of feet of cable required is 305.45.
**********************************************************
Network #2
Cable requirement to connect (11,27) to (88,30) is 93.06 feet.
Cable requirement to connect (88,30) to (95,38) is 26.63 feet.
Cable requirement to connect (95,38) to (84,99) is 77.98 feet.
Cable requirement to connect (84,99) to (142,81) is 76.73 feet.
Number of feet of cable required is 274.40.
**********************************************************
Network #3
Cable requirement to connect (132,73) to (72,111) is 87.02 feet.
Cable requirement to connect (72,111) to (49,86) is 49.97 feet.
Number of feet of cable required is 136.99.

World Final 1992的水题。


完整代码:

/*0.099s*/

#include<cstdio>
#include<cmath>
#include<cfloat>
#include<algorithm>
using namespace std;
const char star[] = {"**********************************************************"};
const int add = 16;

int x[10], y[10], num[10], save[10];

int main()
{
	int n, i, cas = 0;
	double dis, mind;
	while (scanf("%d", &n), n)
	{
		puts(star);
		printf("Network #%d\n", ++cas);
		for (i = 0; i < n; ++i)
		{
			scanf("%d%d", &x[i], &y[i]);
			num[i] = i;
		}
		mind = DBL_MAX;
		do
		{
			dis = 0.0;
			for (i = 0; i < n - 1; ++i)
				dis += hypot(x[num[i + 1]] - x[num[i]], y[num[i + 1]] - y[num[i]]);
			if (dis < mind)
			{
				mind = dis;
				for (i = 0; i < n; ++i)
					save[i] = num[i];
			}
		}
		while (next_permutation(num, num + n));
		for (i = 0; i < n - 1; ++i)
			printf("Cable requirement to connect (%d,%d) to (%d,%d) is %.2f feet.\n", x[save[i]], y[save[i]], x[save[i + 1]], y[save[i + 1]], hypot(x[save[i + 1]] - x[save[i]], y[save[i + 1]] - y[save[i]]) + add);
		printf("Number of feet of cable required is %.2f.\n", mind + add * (n - 1));
	}
	return 0;
}

从零构建企业级多智能体系统:LangGraph 全流程实战 + 部署指南(含代码与架构图) > 在大模型应用爆发的今天,如何构建一个可协作、可调试、可部署的多智能体系统?LangGraph 正在成为工程师的新宠。本文从原理剖析、流程建模、代码实战到前后端部署,手把手带你用 LangGraph 构建一个企业级 AI 助理系统,整合财务分析、法务审阅、报告生成与图表可视化等 Agent 模块,全面打通从用户输入到报告输出的全链路闭环。适合有工程思维的 AI 架构师、Agent 研发人员、以及大模型项目实践者。 阅读详情

相关推荐

深入STM32 USB OTG FS:从官方MSC例程到实战双存储设备移植全记录

本文详细解析了STM32 USB OTG FS在双存储设备开发中的实战应用,从协议栈底层机制到SD卡/SPI Flash同步挂载的实现。通过优化SDIO接口和SPI Flash驱动,结合USB MSC类的关键实现,提供了完整的解决方案和性能优化策略,适合嵌入式开发者参考。

weixin_28366475的博客 379

[PAT-Advanced] A1014 Waiting in Line (30)

文章目录A1014 Waiting in Line (30分)Input Specification:Output Specification:Sample Input:Sample Output:CodeAnalysis 作者: CHEN, Yue 单位: 浙江大学 时间限制: 400 ms 内存限制: 64 MB 代码长度限制: 16 KB A1014 Waiting in Line (30分...

Duke 283

【可信数据空间-连接器技术架构设计方案】

一句话概括连接器是可信数据空间的“数据保镖”和“外交官”。连接器就是一个部署在你本地的软件代理,它代表你安全地对外提供数据服务,确保在共享数据价值的同时,牢牢守住数据的所有权和控制权。它是实现“数据可用不可见”这一理想的关键技术部件。一个生动的比喻:银行的金库和接待员想象一下,你的数据就是藏在银行金库里的黄金和钞票。金库(你的内部数据库): 绝对安全,外人绝对不能进。接待员(连接器): 坐在银行大厅里,负责与客户打交道。客户向接待员提出请求:“我想取1000元。

u014716614的博客 2302

uva 216 Getting in Line

题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=152 题目描述: Getting in Line  Computer networking requi

心之所向,无惧无悔! 942

可乐学习NVMe之一:为什么SSD需要NVMe

1. NVMe SSD 结构简图 整体来看,NVMe SSD可以分为三部分,host端的驱动NVMe Driver、PCIe+NVMe实现的控制器以及NAND Flash+DDR4/DDR5存储介质。 芯片回片后Host侧软件或者驱动开发主要在应用层,通过一些测试工具进行benchmark跑分测试,performance性能分析,latency分析、stress-testing等等: 那么,接下来阐述为什么SSD需要NVMe,并再后续的文章介绍NVMe协议分析,个人针对协议的理解,如果有不当之处,还请各

Lucky 3183

Tomcat启动过程中cmd窗口(控制台)中文乱码的问题

tomcat启动时,启动过程日志中文乱码的处理方法。

寻码启示 1956

UVA - 216 Getting in Line (全排列枚举 和 回溯两种解法)

Getting in Line  Computer networking requires that the computers in the network be linked. This problem considers a ``linear" network in which the computers are chained together so that e

小G的ACM之路 1167

Jetson AGX Orin边缘AI实战:用YOLOv8做目标检测,我的环境配置踩坑与优化记录

本文详细记录了在Jetson AGX Orin上部署YOLOv8目标检测模型的环境配置与优化过程。从JetPack版本确认、PyTorch安装陷阱到Torchvision编译技巧,再到YOLOv8部署和系统级优化,提供了完整的实战指南。特别针对边缘AI设备的特性,分享了CUDA加速、内存管理等性能调优经验,帮助开发者高效完成工业级AI应用部署。

weixin_30839881的博客 389

uva216 - Getting in Line

一道暴力的题目。。枚举出来就好了。。 一开始用自己写全排列都是WA 。。 可能是字典序什么的问题。。然后用了STL的全排列 题目 Getting in Line Computer networking requires that the computers in the network be linked. This proble...

aiezhen1717的博客 140

基于 YOLOv26 的 PCB 板缺陷检测:工业级视觉实战

本文提出了一种基于YOLOv26的PCB板缺陷检测系统,通过深度学习技术实现对PCB板缺陷的自动化检测。系统能够识别短路、开路、焊点不良等8种常见缺陷,具有高精度、多类别分类和实时推理等优势。文章详细介绍了系统架构,包括数据采集、预处理、YOLOv26模型检测和后处理模块。在代码实现部分,给出了环境配置、数据预处理与增强的具体方法,使用Albumentations库进行图像增强处理。该系统为电子制造业提供了高效、准确的PCB质量检测解决方案,显著提升了检测效率和准确性。

一键难忘的博客 344

AI Agent在医疗诊断中的智能应用研究

本文探讨了AIAgent在医疗诊断中的智能应用,分析了其技术原理、实际案例及发展挑战。AIAgent通过机器学习算法处理医疗数据,提升诊断准确性和效率,市场规模预计2025年达200亿美元。核心技术包括数据预处理、深度学习模型和隐私保护方法。应用案例涵盖肺癌筛查、阿尔茨海默病预测等,但面临数据偏差、伦理责任等挑战。未来趋势包括多模态学习、个性化医疗和量子计算融合。随着技术优化和伦理完善,AIAgent将成为医疗体系的重要组成部分。

郑伟强dev的专栏 104

UVa 216 Getting in Line

题目要求在平面上给定n个点(2≤n≤8),将它们连成一条链,使得总电缆长度最小。每段电缆长度为两点欧氏距离加16英尺。输入包含多个数据集,每个数据集给出n个点的坐标。输出要求:对于每个数据集,输出网络编号、最优连接顺序下各段电缆长度及总长度,不同数据集间用&quot;*&quot;分隔。解题思路是枚举所有排列组合,计算每种排列的总长度,取最小值。由于n≤8,全排列枚举可行。代码实现了预处理点对距离、枚举全排列、计算最优解并按要求格式化输出的完整流程。

寂静山林 94

使用C#实现的多人语音视频系统:WebSocket与WebRTC集成

通过上述的代码示例,我们可以使用C#编写一个多人语音视频系统,该系统集成了WebSocket和WebRTC技术。当然,这只是一个简单的示例,实际的多人语音视频系统可能需要更多的功能和优化。通过结合这两种技术,我们可以实现实时的语音和视频通信,支持多人同时参与。在上述代码中,我们创建了一个WebSocket服务器,监听在本地的8080端口,并创建了一个WebRTC连接。接下来,我们将详细介绍如何使用C#编写一个多人语音视频系统,包括使用WebSocket建立连接和使用WebRTC进行实时通信。

TjsReact的博客 1671

uva 216 Getting in Line 最短路,全排列暴力做法

题目给出离散的点,要求求出一笔把所有点都连上的最短路径。 最多才8个点,果断用暴力求。 用next_permutation举出全排列,计算出路程,记录最短路径。 这题也可以用dfs回溯暴力,但是用最小生成树要小心一点,最小生成树求的是最小连通图,而不是连成一条,不能用Kruscal,Prim算法修改一下也可以使用,改成选点时仅考虑头尾两点即可。 代码: #include #includ

水果君の日常 2162

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

UVa 216 - Getting in Line

题目:给你n台电脑所在的平面位置,求把他们连乘线型网络需要的最小的网线长度。 分析:搜索,枚举。           因为数据规模很小,枚举所有电脑的全排列,每一个排列对应一种连线方式。           枚举所有的连线方式,找到其中最小的,输出路径即可。 说明:开始以为是最短路或者最小生成树类似物(⊙_⊙)。 #include #include #include #includ

小白菜又菜 1387

温度PID控制PLC程序

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

【ICPC-189】uva 216 - Getting in Line

点击打开链接 题目意思:给定n个点,求出点之间的最小的距离之和 解题思路:1 利用单源最短路算法 2 枚举点构成序列的全排列,求出所有排列的中的最小,并且记录下对应点的位置 代码: //要求单源最短路径,对于这一题我们知道点的个数最多为8,那么我们可以采用枚举每个点的顺序位置,就是去枚举这个点全排列,然后得到最小值,并且保存下序列的位置 #include &lt...

藏经阁 | 玄苦 1409

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

uva 216 - Getting in Line

点击打开链接 题目意思:给定n个点,求出点之间的最小的距离之和 解题思路:1 利用单源最短路算法 2 枚举点构成序列的全排列,求出所有排列的中的最小,并且记录下对应点的位置 代码: //要求单源最短路径,对于这一题我们知道点的个数最多为8,那么我们可以采用枚举每个点的顺序位置,就是去枚举这个点全排列,然后得到最小值,并且保存下序列的位置 #include &amp;lt;iostr...

我是传奇 137

UVa OJ 题解索引

寂静山林 795

UVa 11264 Coin Collector (选硬币&贪心好题)

思路: 1. 你肯定注意到了,面值最大的硬币c[n-1]必须要选。(反证:如果花了sum元却没有选中它,可知sum<c[n-1],于是用m+c[n-1]元去兑换可以得到一个更优解。) 2. 贪心的关键:假设S(i)是c[1]…c[i] 中那些被选中的货币的面值的和。那么一定有 S(i) < c[i+1]。 3. 所以可以构造一个这样的序列出来。按照2中所说,如果有 S(i-1) < c[i]且S(i) =S(i-1)+c[i]<c[i+1],那么c[i]将被选中。 完整代码:

AC,∑ndless 4699

UVa 256 Quirksome Squares (枚举||二次同余)

直接从0~9999枚举即可,因为等式右边一定是个完全平方数。 PS:此题可抽象成一个数论的问题:(部分解法参考了这篇文章) 求解4个二元二次丢番图方程 (x+y)^2=2mx+y,m=10^k / 2 = 2^(k-1)*5^(2k),k=1,2,3,4 令x+y=t,上式化为 t^2-2mt+(2m-1)y=0(由于0<=t^2<10^2k,所以0<=t<10^k) 进而 (t-m)^2=(1-2m)y+m^2 此方程的等价于求解二次同余式

AC,∑ndless 3444

UVa 10049 Self-describing Sequence (自描述序列&二分递推)

10049 - Self-describing Sequence Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=990 Solomon Golomb's self­des

AC,∑ndless 3143

UVa 108 Maximum Sum (贪心&最大子矩阵和)

108 - Maximum Sum Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=44 Background A problem that is simple

AC,∑ndless 2786

UVa 10057 A mid-summer night's dream. (二分&可以取哪些作为中位数?)

输出注意: 第一个数是最小的A,第二个数是在数列{Xn}中有多少个数可以是A,第三个数是在有多少个数可以是A。 完整代码:

AC,∑ndless 2502
上一篇: HDU 4497 GCD and LCM (数论&组合数学)
下一篇: UVa 639 Don't Get Rooked (DFS好题)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址