uva-216 - Getting in Line

drm 之modes #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <time.h&... 阅读详情

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.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int arr[8];
int ans[8];

int x[8], y[8];

double dist(int a, int b)
{
    return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
}

int main()
{
    int n;
    int cases = 1;
    while(cin >> n){
        if(!n) break;


        for(int i = 0; i < n; i++){
            cin >> x[i] >> y[i];
            arr[i] = i;
        }

        double mini = 1000000;
        double distance;
        do{
            distance = 0;
            for(int i = 0; i < n-1; i++)
                distance += dist(arr[i], arr[i+1]);

            if(distance < mini){
                mini = distance;
                for(int i = 0; i < n; i++)
                    ans[i] = arr[i];
            }
        }while(next_permutation(arr, arr+n));

        cout << "**********************************************************" << endl;
        cout << "Network #" << cases++ << endl;
        for(int i = 0; i < n-1; i++)
            printf("Cable requirement to connect (%d,%d) to (%d,%d) is %.2f feet.\n", x[ans[i]], y[ans[i]]
                   , x[ans[i+1]], y[ans[i+1]], dist(ans[i], ans[i+1])+16);
        printf("Number of feet of cable required is %.2f.\n", mini+(n-1)*16);
    }
    return 0;
}





基于FreeRTOS与MQTT的物联网技术应用系列——步进电机控制(三)SD卡驱动、FatFS等的移植和ini配置文件读取的实现 本文实现了基于STM32F107VC的金牛开发板的基于SPI模式的SD卡驱动和FatFS的移植,以及利用minini库对ini配置信息文件进行读取。 阅读详情

相关推荐

BEVFormer详解

BEVFormer 是将Transformer架构的自注意机制与BEV视图中3D检测结合起来的一种纯视觉目标检测方案。对于纯视觉的BEV检测方案,其中的重中之重就是如何将2D的图像特征映射到3D空间的BEV栅格,既然是映射关系,那就有前行投影和反向查询两种机制。前向投影是基于深度估计的方法,参考基于深度估计的BEV视图转换方法,典型代表为LSS。反向查询方法思路为先将BEV栅格在Z方向上进行lift提升,然后再映射到图像特征图上进行特征查询。BEVFormer 就是基于这种机制进行2D图像特征到3D空间的B

MAX的专栏 4745

UVaOJ216---Getting in Line

216 - Getting in Line Time limit: 3.000 seconds Computer networking requires that the computers in the network be linked. This problem considers a ``linear" network in which the computers are

c随遇er安的专栏 607

【RK3588 NPU性能调优实战】多线程异步推理YOLOv5,榨干6TOPS算力

本文详细解析了如何在RK3588 NPU上通过多线程异步推理优化YOLOv5目标检测性能,实现6TOPS算力的最大化利用。通过线程池设计、流水线化帧处理及避开内存带宽瓶颈等技巧,将NPU利用率从30%提升至82%,帧率显著提高至61.2FPS。文章还提供了环境配置、代码实现及性能对比数据,助力开发者高效部署AI模型。

weixin_29034963的博客 340

uva 216 Getting in Line

递归枚举应用,递归枚举所有可能出现的序列,在递归里面取最优的一组就行了,注意当当前的总长已经超过最小的总长的时候递归就可以回溯了。 #include #include #include #include struct pos { double x; double y; }; struct pos all_pos[10]; struct pos serial[10]; stru

皓首不倦 不负少年 600

IS-IS协议深度解析(二):LSDB同步机制与骨干网实战部署

本文深度解析IS-IS协议的LSDB同步机制与骨干网实战部署。详细阐述了DIS角色如何通过CSNP/PSNP报文高效管理链路状态数据库同步,并与OSPF DR机制进行对比。重点介绍了Level-2骨干网作为逻辑高速公路系统的工作原理,以及通过ATT比特位实现跨区域路由的自动化。最后提供了高可靠性骨干网的实战配置要点与验证方法。

kite3的博客 644

基于Ansys Fluent和Mechanical的血管稳态流固耦合模型

流固耦合模型在医学中也会被用到,本次小编为大家带来针对人造血管内血液流动的仿真实例。 在开物云平台上找到Workbench 点击进入:https://cloud.yuansuan.cn/?user_source=community 在左侧的Toolbox中找到对应的模块:Fluid Flow(Fluent)和Static Structure 双击“Geometry”,进入建模功能 文件-打开-找到保存的模型文件 退回到主界面,在fluid flow(Fluent)中找到mesh

huasheng233的博客 3909

UVA216-Getting in Line

题意:给出不超过8个点的坐标,要求所铺的电路最短 思路:因为点的数量最多不会超过8个,所以可以直接暴力搜索。利用全排列,将所有可能的情况都计算一次,更新最短路进。 #include #include #include using namespace std; int b[8], c[8]; struct node{ int x, y; }a[10]; double lenth(do

懒人一枚。 745

uniApp微信小程序:error: 60001 request:fail errcode:-101 cronet error code:-101error_msg:net::ERR CONNECTI

uni-app微信小程序域名访问报error 60001 request:fail errcode:-101,解决Uniapp微信小程序报600001错误,uni.request()接口请求报错,服务器更换SSL证书后,uniapp微信小程序出现`request:fail errcode:-101`问题分析与解决,服务器更换ssl证书后,手机访问微信小程序异常,微信小程序更换SSL证书后出现请求报错,服务器更换SSL证书,微信小程序报600001,小程序反应偶尔出现request:fail errcode:

✅ 精选推荐文章 4583

Uva216—— Getting in Line

题目的意思求n个点连起来的最短距离。n最大为8,直接枚举排列的所以情况,然后求最短的距离,最短距离等于连线上的每两个点的距离加上16的和. 点的排序可以多种情况,只要找到最短距离就行。枚举排列用next_permutation函数。 代码: #include #include #include #include using namespace std; int n,

XD 500

【Leetcode】269.火星词典(Hard)

应用拓扑排序

明朗晨光的专栏 768

域适应分类:MCD论文笔记——Maximum Classifier Discrepancy for Unsupervised Domain Adaptation

域适应分类:MCD论文笔记——Maximum Classifier Discrepancy for Unsupervised Domain Adaptation

qq_50001789的博客 1005

UVA216 - Getting in Line(哈密顿图)

题目: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=90847#problem/C 思路: 经过每条边一次。 递归回溯。 AC. #include #include #include #include #include #include using namespace std; const int inf =

Halo 676

ABAP BDC 处理踩坑笔记:把错误挡在录制之前,把稳定做进每一行 BDCDATA

本文总结了SAP BDC(批输入)开发中的常见问题和解决方案。重点包括:1)理解BDCDATA本质是模拟人工操作而非直接操作数据库;2)数据格式化技巧,如金额、日期、物料号等字段的标准化处理;3)通过CTU_PARAMS参数控制执行环境,确保屏幕尺寸和更新模式一致;4)不要依赖sy-subrc,应通过解析MESSTAB消息判断业务是否成功;5)录制阶段的常见陷阱及解决方法;6)疑难问题的系统性解决思路;7)建议建立完善的错误处理机制,包括日志记录和重跑功能。文章提供了实用的ABAP代码示例和配置建议,帮助开

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 265

UVA 216 Getting in Line

UVA 216 Getting in Line 深搜回溯,找出最短的路径。。搜索过程中保存下路径。最后输出。。 其实也可以用全排列的next_permutation 暴力找出最短。。 #include #include #include int n; double x[10], y[10]; int vis[10]; int lu[10]; int minlu[10];

Remilia's 1185

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

UVa216 Getting in Line

给你几个点,要求一条线长度最短,数据量较小,直接暴力了,next_permutation()遍历所有可能。#include #include #include #include #include using namespace std; const int N = 10; const double INF = 1<<29; int number; //例子次序 int test; /

江枭的专栏 561

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

UVA 216 Getting in Line

UVA-216题意:给出若干个点,只能用一条线连接,求最小费用(?反正是距离+16.0)。 解题思路:深搜暴力枚举第i个连接的点,计算下总和。注意下输出。漏了一个 . 我WA了2次。/************************************************************************* > File Name: UVA-216.cpp >

QzNarsh的博客 449

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

UVa 216 Getting in Line

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

寂静山林 91

Getting in Line UVA, 216

#include #include #include #include #include using namespace std; struct Node {     int x;     int y; }node[10]; struct Ans {     double goal;     int i; }ans[41000]; //i为全排列中的编号,goal为得

ICDI的博客 393

UVA 216(Getting in Line)回溯

题目链接:https://vjudge.net/problem/UVA-216题意:给出n个点,求n-1条路连接所有点,路径之和最短注意:要在每条路的距离加上16(题目说的),刚开始想到的是用回溯,毕竟现在在做这个专题,要用一个数组记录路径!回溯的代码玄学WA,找不到原因,求大神指教#include&lt;bits/stdc++.h&gt; #define LL long long #define...

Eknight123的博客 570

Uva 216 Getting in Line

枚举给定点的坐标间距离和的最小值~~数据量小,暴力枚举即可~~ #include #include #include #include #include #include using namespace std; typedef struct _Poi

Xiao_Peng 344

UVA 216 - Getting in Line

#include #include #include using namespace std; int main() { int num, arr[10][2], brr[10], order[10], count = 0; while (scanf("%d", &num), num) { double min = 1000000; for (int i = 0; i < nu

Bingo 1691

UVA 216-Getting in Line

UVA 216-Getting in Line题目大意:给出坐标,求出全部连起来的最短路,每个连线长度要另外加16 解题思路:可以列子集,也可以回溯,子集因为这题情况少可以用,回溯则是比较通用,一下是用回溯的代码#include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include <string

ZeroLH00的博客 408

uva216 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 each is connected to exactly t

王旻宇 540

[枚举]Getting in Line UVA 216

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 tha

九问的烦恼 1135

UVA 216 Getting in Line dfs

点击打开题目链接 平面上有一些点,求一笔将所有点连起来的最短距离(注意每次连都要加上16) 由于最多只有8个点,暴力全排列即可 方法一:dfs #include #include #include #include #include using namespace std; const int INF = 0xfffffff; const int MAXN = 10; in

Houheshuai的专栏 510
上一篇: uva-110-Meta-Loopless Sorts
下一篇: uva-301 - Transportation
HuanTongH
博客等级 码龄12年 7粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值