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

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

 

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

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 = < xiyi ><tex2html_verbatim_mark> . 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<tex2html_verbatim_mark> -coordinates.

Write a program that, given a set of n<tex2html_verbatim_mark> points in the plane, computes the shortest closed tour that connects the points according to John's strategy.

 

 

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<tex2html_verbatim_mark> coordinate. White spaces can occur freely in input. The input data are correct.

 

 

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.

 

Note: 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<tex2html_verbatim_mark> and y<tex2html_verbatim_mark>coordinates. The second point, for example, has the x<tex2html_verbatim_mark> coordinate 2, and the y<tex2html_verbatim_mark> coordinate 3. The result for each data set is the tour length, (6.47 for the first data set in the given example).

 

 

 

3 1 12 33 14 1 1 2 33 14 2

 

 

 

6.477.89

 

可以把一个人的往返看作是两个人从起点同时出发走到终点,两人走到的点不重复

则对于一个点,要么一个人过去,要么另一个人过去(不需要区分到底是哪个人)

 

1 /*by SilverN*/ 2 #include
3 #include
4 #include
5 #include
6 #include
7 using namespace std; 8 const int mxn=1024; 9 int x[mxn],y[mxn];10 double mp[mxn][mxn];11 double f[mxn][mxn];12 int n;13 int main(){14 while(scanf("%d",&n)!=EOF){15 memset(f,11,sizeof(f));16 int i,j;17 for(i=1;i<=n;i++){18 scanf("%d%d",&x[i],&y[i]);19 }20 for(i=1;i<=n;i++){21 for(j=1;j<=n;j++){22 mp[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));23 }24 }25 for(i=n-1;i>=2;i--){
//i倒推 26 for(j=1;j

 

转载于:https://www.cnblogs.com/SilverNebula/p/5589518.html

你可能感兴趣的文章
使用Redis构建文章投票网站(Java)
查看>>
见微知著 —— Redis 字符串内部结构源码分析
查看>>
Command './js-ant' failed to execute
查看>>
阿里云NFS NAS数据保护实战
查看>>
Spring cloud配置客户端
查看>>
产品研发项目管理软件哪个好?
查看>>
【阿里云北京峰会】一图看懂机器学习PAI如何帮助企业应用智能化升级
查看>>
ansible playbook使用总结
查看>>
Android API中文文档(111) —— MailTo
查看>>
Linux 中如何卸载已安装的软件
查看>>
thinkphp 3.2 增加每页显示条数
查看>>
oracle日常简单数据备份与还原
查看>>
我的友情链接
查看>>
黑马程序员__反射总结
查看>>
Scala学习笔记(5)-类和方法
查看>>
Quartz原理
查看>>
完全卸载oracle|oracle卸载|彻底卸载oracle
查看>>
垃圾收集基础
查看>>
Docker安装及基本命令
查看>>
控制namenode检查点发生的频率
查看>>