博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2677 Tour
阅读量:6177 次
发布时间:2019-06-21

本文共 2234 字,大约阅读时间需要 7 分钟。

双调欧几里得 DP

Tour
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3581   Accepted: 1596

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

31 12 33 141 12 33 14 2

Sample Output

6.477.89

Source

[]   [Go Back]   []   []

#include 
#include
#include
#include
#include
using namespace std;double x[100],y[100];double dist(int a,int b){ return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));}double dp[100][100];int n;int main(){ while(cin>>n) { for(int i=1;i<=n;i++) { cin>>x[i]>>y[i]; } for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { dp[i][j]=99999999; } } dp[1][1]=0; dp[2][1]=dist(1,2); for(int i=1;i<=n;i++) { for(int j=1;j

转载地址:http://wfzda.baihongyu.com/

你可能感兴趣的文章
有够老土 美国间谍刚刚用上iPhone等新款数码产品
查看>>
任正非坚决反对年终奖:强调项目奖、及时奖
查看>>
学习Docker的User Namespace
查看>>
初识三层结构
查看>>
javascript 动态统计文本域输入字符个数
查看>>
Symantec Backup Exec 2012 Agent for Linux 卸载
查看>>
经典算法题每日演练——第十一题 Bitmap算法
查看>>
子类继承父类实现父类的代理方法
查看>>
框架嵌套实例
查看>>
IOS UISlider用法总结
查看>>
jackson处理boolean类型的注意点
查看>>
IAR中的Zstack工程产生的.hex通过SmartRF Flash Programmer烧录到CC2530
查看>>
Object-C---&gt;Swift之(六)函数类型
查看>>
【Android】设置EditText为仅输入数字且最多只能有两位数字
查看>>
很容易学习的JQuery库 : (一) 简介
查看>>
搬家与流式处理
查看>>
syslog协议介绍
查看>>
各种排序算法的总结和比较
查看>>
继承和多态
查看>>
用EJB进行事务管理
查看>>