poj-2677 动态规划、双调欧几里得旅行商

简介: Tour Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2699   Accepted: 1193 Description John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a
Tour
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2699   Accepted: 1193

Description

John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must determine the shortest closed tour that connects his destinations. Each destination is represented by a point in the plane pi = < xi,yi >. John uses the following strategy: he starts from the leftmost point, then he goes strictly left to right to the rightmost point, and then he goes strictly right back to the starting point. It is known that the points have distinct x-coordinates. Write a program that, given a set of n points in the plane, computes the shortest closed tour that connects the points according to John's strategy.

Input

The program input is from a text file. Each data set in the file stands for a particular set of points. For each set of points the data set contains the number of points, and the point coordinates in ascending order of the x coordinate. White spaces can occur freely in input. The input data are correct.

Output

For each set of data, your program should print the result to the standard output from the beginning of a line. The tour length, a floating-point number with two fractional digits, represents the result. An input/output sample is in the table below. Here there are two data sets. The first one contains 3 points specified by their x and y coordinates. The second point, for example, has the x coordinate 2, and the y coordinate 3. The result for each data set is the tour length, (6.47 for the first data set in the given example).

Sample Input

3
1 1
2 3
3 1
4
1 1
2 3
3 1
4 2

Sample Output

6.47
7.89

微笑题目大意:给出一些点的坐标,顺序为从左到右。飞行员小明要飞一段旅程。

微笑分析:先略。


目录
相关文章
|
5月前
|
存储
【洛谷 P2437】蜜蜂路线 题解(递归+记忆化搜索+高精度)
蜜蜂路线问题:蜜蜂从蜂房$m$到$n$($m&lt;n$)按数字递增爬行。给定$m$和$n$,求路线数。示例:$m=1$,$n=14$,输出$377$。100%数据$1\leq m,n\leq1000$。使用斐波那契序列优化,高精度处理大数。代码实现斐波那契存储并动态规划求解。
83 0
|
6月前
|
机器学习/深度学习 算法 C++
【动态规划】C++算法:403.青蛙过河
【动态规划】C++算法:403.青蛙过河
|
6月前
|
Go
[leetcode 差分数组] 拼车 M
[leetcode 差分数组] 拼车 M
|
人工智能 算法 测试技术
LeetCode 双周赛 101,DP / 中位数贪心 / 裴蜀定理 / Dijkstra / 最小环
这周比较忙,上周末的双周赛题解现在才更新,虽迟但到哈。上周末这场是 LeetCode 第 101 场双周赛,整体有点难度,第 3 题似乎比第 4 题还难一些。
97 0
|
算法
算法简单题,吾辈重拳出击 - 动态规划之爬楼梯
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
|
索引
LeetCode 1337. 矩阵中战斗力最弱的 K 行
给你一个大小为 m * n 的矩阵 mat,矩阵由若干军人和平民组成,分别用 1 和 0 表示。
137 0
|
算法 C++
算法 |【实验5.2】1-深度优先搜索暴力求解旅行商问题
算法 |【实验5.2】1-深度优先搜索暴力求解旅行商问题
510 0
算法 |【实验5.2】1-深度优先搜索暴力求解旅行商问题
|
机器学习/深度学习 传感器 算法
【TSP问题】基于状态转移算法求解旅行商问题附matlab代码
【TSP问题】基于状态转移算法求解旅行商问题附matlab代码
|
机器学习/深度学习 传感器 算法
基于遗传算法求解多旅行商问题同一起点和终点付matlab代码
基于遗传算法求解多旅行商问题同一起点和终点付matlab代码