csu1527: Bounty Hunter
Time Limit:5000MS Memory Limit:131072KB
64bit IO Format:%lld & %llu
Description

Input
Output
Sample Input
2
5
0 1
1 2
2 0
3 2
4 1
3
100 1
200 1
300 1
Sample Output
9.300563079746
400
从0到n-1走过去再走回来经过全部点保证走过的路程最短
如果来回的两条路各自经过的点中,除了0跟n-1外还有其他点是它们都有的,那么显然把这个点单独放在两条路中的一条都会更加好
所以两条路的点必定仅仅有0。n-1两个交集
dp[i][j]:一条路以0,i为两个端点,还有一条路以0,j为两个端点。且包含0跟max(i,j)中的全部点时的最短路程,因为上述原则,必定i,j要有一个大一些,我们设i>j
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct point
{
double x,y;
double dis(point one)
{
return sqrt(pow(x-one.x,2)+pow(y-one.y,2));
}
friend istream & operator >>(istream &is,point &one)
{
is>>one.x>>one.y;
return is;
}
};
point box[600];
double dp[600][600];
int main()
{
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>box[i];
dp[1][0]=box[0].dis(box[1]);
for(int i=1;i<n-2;i++)
{
dp[i+1][i]=1e99;
for(int j=0;j<i;j++)
{
dp[i+1][i]=min(dp[i+1][i],dp[i][j]+box[j].dis(box[i+1]));
dp[i+1][j]=dp[i][j]+box[i].dis(box[i+1]);
}
}
double ans=n==2? 2.0*box[0].dis(box[1]):1e99;
for(int i=0;i<n-2;i++)
ans=min(ans,dp[n-2][i]+box[n-2].dis(box[n-1])+box[i].dis(box[n-1]));
printf("%.9f\n",ans);
}
}
csu1527: Bounty Hunter的更多相关文章
- CodeForcesGym 100753B Bounty Hunter II
Bounty Hunter II Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- How to become a successful bug bounty hunter
出处:https://www.hackerone.com/blog/become-a-successful-bug-bounty-hunter 如果你梦想成为赏金猎人,你的梦想就会成真 - 不要把你的 ...
- CodeForcesGym 100753B Bounty Hunter II 二分图最小路径覆盖
关键在建图 题解:http://www.cnblogs.com/crackpotisback/p/4856159.html 学习:http://www.cnblogs.com/jackiesteed/ ...
- Bug Bounty Reference
https://github.com/ngalongc/bug-bounty-reference/blob/master/README.md#remote-code-execution Bug Bou ...
- Gson解析Json数组
需求:从steam官网获取英雄数据,即为Json数据,并导入到本地数据库 Json数据是这样的 { "result": { "heroes": [ { &quo ...
- ARTIFICIAL INTELLIGENCE FOR GAMES (Ian Millington / John Funge 著)
相关网站:http://www.ai4g.com PART I AI AND GAMESCHAPTER1 INTRODUCTIONCHAPTER2 GAME AIPART II TECHNIQUESC ...
- 《jquery实战》javascript 必知必会(2)
A2 一等公民函数 在传统 OO 语言里,对象包含数据和方法.这些语言里,数据和方法通常是不同的概念:javascript另辟蹊径. 与其他 js 的类型一样,函数可以作为对象处理,如String.N ...
- 《jquery实战》javascript 必知必会(1)
A1 javascript对象的基本原理 JS 的 Object 与其他兄弟面向对象所定义的根本对象,几乎没有什么共同之处. JS 的 Object 一旦创建,它不持有任何数据,而且不表示什么语义. ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
随机推荐
- 【最短路径树】51nod1443 路径和树
并不是什么高端操作并且一些模型会用到 Description 给定一幅无向带权连通图G = (V, E) (这里V是点集,E是边集).从点u开始的最短路径树是这样一幅图G1 = (V, E1),其中E ...
- 网络设备之ospf2
OSPF(Open Shortest Pass First,开放最短路径优先协议),是一个最常用的内部网管协议,是一个链路状态协议. OSPF的特点 OSPF是一种无类路由协议,支持VLSM可变长子网 ...
- kafka异常问题汇总
1.报错:: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.NotLeaderForPartition ...
- DocView mode 2 -- 快捷键
** 启动 C-c C-c 切换DocView和文件内容显示 M-x doc-view-mode 启动主模式 M-x doc-view-minor-mode 启动辅模式 k k ...
- Oracle跟踪分析数据库启动的各个阶段
目录 启动到nomount状态 设置trace 启动数据库到mount状态并打开 查阅trace 查阅trace的另外方法 v$diag_info 视图 演示如下: 启动到nomount状态 SYS@ ...
- [转]构建Python+Selenium2自动化测试环境(二)
构建Python+Selenium2自动化测试环境完成之后,就需要测试支持python的selenium的版本是否都支持在不同浏览器上运行,当前我们分别在三个最通用的浏览器上通过脚本来测试. 1.在I ...
- CentOS6.5的安装及忘记root密码的措施
CentOS6.5的安装及忘记root密码的措施 VMware虚拟机的配置 1.文件->新建->自定义->下一步 2.选择稍后安装操作系统 我们将采用自定义安装,杜绝VMware的一 ...
- MYSQL 权限设置查询
mysql> GRANT RELOAD, SUPER, REPLICATION SLAVE ON *.* TO 'repl'@'192.168.3.%' IDENTIFIED BY PASSWO ...
- Python中你不知道的特性
内置函数print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) 本函数是实现对象以字符串表示的方式格式化输出到流文件对象fil ...
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
先把代码扔上来 E. Field of Wonders time limit per test 3 seconds memory limit per test 256 megabytes input ...