HDU 2224 The shortest path
The shortest path
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1507 Accepted Submission(s): 773
Before you reach the rightmost point Pn, you can only visit the points those have the bigger x-coordinate value. For example, you are at Pi now, then you can only visit Pj(j > i). When you reach Pn, the rule is changed, from now on you can only visit the points those have the smaller x-coordinate value than the point you are in now, for example, you are at Pi now, then you can only visit Pj(j < i). And in the end you back to P1 and the tour is over.
You should visit all points in this tour and you can visit every point only once.
1 1
2 3
3 1
Hint: The way 1 - 3 - 2 - 1 makes the shortest path.
- #include<iostream>
- #include<cmath>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- int n;
- double dis[][],f[][];
- struct nond{
- int x,y;
- }v[];
- int cmp(nond a,nond b){
- if(a.x==b.x) return a.y<b.y;
- return a.x<b.x;
- }
- void pre(){
- for(int i=;i<=n;i++)
- for(int j=i;j<=n;j++)
- dis[i][j]=dis[j][i]=sqrt((double)(v[i].x-v[j].x)*(v[i].x-v[j].x)+(v[i].y-v[j].y)*(v[i].y-v[j].y));
- }
- int main(){
- while(scanf("%d",&n)!=EOF){
- memset(dis,,sizeof(dis));
- for(int i=;i<=n;i++)
- scanf("%d%d",&v[i].x,&v[i].y);
- sort(v+,v++n,cmp);
- pre();
- f[][]=f[][]=dis[][];
- f[][]=*dis[][];
- for(int i=;i<=n;i++){
- for(int j=;j<i-;j++)
- f[i][j]=f[j][i]=f[i-][j]+dis[i][i-];
- f[i][i-]=f[i-][i]=f[i][i]=0x7f7f7f7f;
- for(int j=;j<=i-;j++)
- f[i-][i]=f[i][i-]=min(f[i][i-],f[j][i-]+dis[j][i]);
- for(int j=;j<=i;j++)
- f[i][i]=min(f[i][i],f[j][i]+dis[j][i]);
- }
- printf("%.2lf\n",f[n][n]);
- }
- }
HDU 2224 The shortest path的更多相关文章
- Hdu 4725 The Shortest Path in Nya Graph (spfa)
题目链接: Hdu 4725 The Shortest Path in Nya Graph 题目描述: 有n个点,m条边,每经过路i需要wi元.并且每一个点都有自己所在的层.一个点都乡里的层需要花费c ...
- HDU 4725 The Shortest Path in Nya Graph [构造 + 最短路]
HDU - 4725 The Shortest Path in Nya Graph http://acm.hdu.edu.cn/showproblem.php?pid=4725 This is a v ...
- HDU 4725 The Shortest Path in Nya Graph
he Shortest Path in Nya Graph Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged o ...
- hdu 2807 The Shortest Path(矩阵+floyd)
The Shortest Path Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- (中等) HDU 4725 The Shortest Path in Nya Graph,Dijkstra+加点。
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...
- HDU 4725 The Shortest Path in Nya Graph(构图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4725 The Shortest Path in Nya Graph (最短路)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- HDU 4725 The Shortest Path in Nya Graph(最短路径)(2013 ACM/ICPC Asia Regional Online ―― Warmup2)
Description This is a very easy problem, your task is just calculate el camino mas corto en un grafi ...
- hdu 4725 The Shortest Path in Nya Graph (最短路+建图)
The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
随机推荐
- Struts2 中 result type=”json” 的参数解释
转自:http://wangquanhpu.iteye.com/blog/1461750 1, ignoreHierarchy 参数:表示是否忽略等级,也就是继承关系,比如:TestAction 继承 ...
- php处理类
Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...
- C++中const用法
1.const和指针: 如果const出现在星号左边,表示被指物是常量:如果出现在星号右边,表示指针自身是常量:如果出现在星号两边,表示被指物和指针两者都是常量. char greet[] = “He ...
- BZOJ 2101 DP+优化
思路: http://www.cnblogs.com/exponent/archive/2011/08/14/2137849.html f[i,i+len]=sum[i,i+len]-min(f[i+ ...
- OPPO R11 R11plus系列 解锁BootLoader ROOT Xposed 你的手机你做主
首先准备好所有要使用到的文件 下载链接:https://share.weiyun.com/5WgQHtx 步骤1. 首先安装驱动 解压后执行 Install.bat 部分电脑需要禁用驱动程序签名才可以 ...
- 【PostgreSQL-9.6.3】表继承
表继承是PostgreSQL特有的,子表可以从父表中继承字段和一些属性.例如: --创建一张表“persons”作为父表: test=# create table persons ( test(# i ...
- 图像局部显著性—点特征(Fast)
fast作为几乎最快的角点检测算法,一般说明不附带描述子.参考综述:图像的显著性检测--点特征 详细内容,请拜访原=文章:Fast特征点检测算法 在局部特征点检测快速发展的时候,人们对于特征的认识也越 ...
- java JDBC连接 Sqlserver 非默认的实例名问题
一般我们在连接数据库的时候都是用的默认实例名,今天遇到了用非默认是实例名:连接代码如下(Java): <property name="url" value="jdb ...
- Entity FrameWork 操作使用详情
Entity FrameWork 是以ADO.net为基础发展的ORM解决方案. 一.安装Entity FrameWork框架 二.添加ADO.Net实体数据模型 三.EF插入数据 using Sys ...
- " \t\r\n\f"是什么意思
空格字符 \t 制表符 \r 回车符 \n 换行符 \f 换页符