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 ...
随机推荐
- 软件-版本控制:VCS(版本控制系统)
ylbtech-软件-版本控制:VCS(版本控制系统) 版本控制系统(Version Control System),是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.版本控制系统 ...
- preg_replace数组的用法
$string = 'The quick brown fox jumped over the lazy dog.';$patterns = array();$patterns[2] = '/quick ...
- Electron桌面应用:环境搭建
目录 一.简介 二.市场 三.安装 1.安装node版本 2.安装国内的npm包管理器 3.安装electron 4.验证electron否安装成功 5.使用git克隆一个electron简单的项目, ...
- Windows:Word,PPT,EXCEL com+组件配置
本文所涉及到配置前提: 服务器必须安装Office套件(Word,PPT,Excel) 第一部分 Word Com+组件权限配置 1.cmd模式输入dcomcnfg 2.找到Microsoft Wor ...
- 一种压缩图片的方法---Machine learning 之 K-Means
背景描述: RGB编码:对于一个直接用24bit表示每一个而像素的图像来说,每一个pixel使用8-bit无符号整数(0-255)来表示红or绿or蓝. 压缩目的: 将128x128大小的图片由原来的 ...
- Quartz 表达式的学习
只记录用到过的,不全面 Quartz版本:quartz-all-1.6.0.jar 先看图 其他示例: 0 5,6,13 * * ? 意义:每日5:00,6:00,13:00 被触发 0 10,30 ...
- 苹果双系统win8.1遇到的一些问题
MacBook air是一款不错的电脑,详细没研究就不叙述好与坏了.只此记录自己使用这款笔记本遇到的问题. 一.安装双系统win8.1 1.下载镜像文件—>拷贝到ios内存中,一个8GU盘.ht ...
- 手动触发dom节点事件代码
在爬代码过程中,碰到一个稀奇古怪的问题.需要手工修改select的值,然后手动触发select的change事件,但使用网络上查到的通过trigger.onchange()事件触发都不执行,没办法,只 ...
- mySQL用代码添加表格内容 删除数据方法
通过代码对表格内容操作: 1.添加数据insert into Info values('p009','张三',1,'n001','2016-8-30 12:9:8') ; 给特定的列添加数据inser ...
- 45.4.7 序列:USER_SEQUENCES(SEQ)
45.4.7 序列:USER_SEQUENCES(SEQ) 要显示序列的属性,可以查询USER_SEQUENCES 数据字典视图.该视图也能用公有同义词SEQ 进行查询.USER_SEQUENCES ...