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的更多相关文章

  1. CodeForcesGym 100753B Bounty Hunter II

    Bounty Hunter II Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...

  2. How to become a successful bug bounty hunter

    出处:https://www.hackerone.com/blog/become-a-successful-bug-bounty-hunter 如果你梦想成为赏金猎人,你的梦想就会成真 - 不要把你的 ...

  3. CodeForcesGym 100753B Bounty Hunter II 二分图最小路径覆盖

    关键在建图 题解:http://www.cnblogs.com/crackpotisback/p/4856159.html 学习:http://www.cnblogs.com/jackiesteed/ ...

  4. Bug Bounty Reference

    https://github.com/ngalongc/bug-bounty-reference/blob/master/README.md#remote-code-execution Bug Bou ...

  5. Gson解析Json数组

    需求:从steam官网获取英雄数据,即为Json数据,并导入到本地数据库 Json数据是这样的 { "result": { "heroes": [ { &quo ...

  6. ARTIFICIAL INTELLIGENCE FOR GAMES (Ian Millington / John Funge 著)

    相关网站:http://www.ai4g.com PART I AI AND GAMESCHAPTER1 INTRODUCTIONCHAPTER2 GAME AIPART II TECHNIQUESC ...

  7. 《jquery实战》javascript 必知必会(2)

    A2 一等公民函数 在传统 OO 语言里,对象包含数据和方法.这些语言里,数据和方法通常是不同的概念:javascript另辟蹊径. 与其他 js 的类型一样,函数可以作为对象处理,如String.N ...

  8. 《jquery实战》javascript 必知必会(1)

    A1 javascript对象的基本原理 JS 的 Object 与其他兄弟面向对象所定义的根本对象,几乎没有什么共同之处. JS 的 Object 一旦创建,它不持有任何数据,而且不表示什么语义. ...

  9. 五、Pandas玩转数据

    Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...

随机推荐

  1. 【Python学习之一】list与tuple

    list -> [] list是python内置的有序集合数据类型,可随时添加和删除元素.例如:创建一个动物的列表: animal = ['cat', 'dog', 'pig' len()函数可 ...

  2. python--网络编程之socket

    一 . 网络编程 CS架构 客户端服务端架构 服务端:提供服务的 客户端:享受服务的 BS架构:浏览器和服务端 网络通信流程: 集线器:将所有连接上它的电脑全部联通起来 交换机:升级版的集线器 网卡: ...

  3. Python-求解两个字符串的最长公共子序列

    一.问题描述 给定两个字符串,求解这两个字符串的最长公共子序列(Longest Common Sequence).比如字符串1:BDCABA:字符串2:ABCBDAB.则这两个字符串的最长公共子序列长 ...

  4. C++ 实验六

    Part.2 // 合并两个文件内容到一个新文件中. // 文件名均从键盘输入 #include <iostream> #include <fstream> #include ...

  5. UVa 10534 DP LIS Wavio Sequence

    两边算一下LIS就出来了,因为数据比较大,所以需要二分优化一下. #include <iostream> #include <cstdio> #include <cstr ...

  6. 关于MongoDB分布式高可用集群实现

    一.环境准备 1.本例使用3台Linux主机,IP地址如下: 点击(此处)折叠或打开 Server B Server C 2.根据需要,开启相应主机防火墙的相关端口.本次需要用到3台主机,所以开启这3 ...

  7. 设置Putty 字体 颜色 全屏

    效果 1.   字体 2.全屏 3. 颜色 Window->Colours->Default Foreground->Modify设置(我喜欢绿色设置:R:0 G:255 B:0) ...

  8. NYOJ 219 An problem about date

    An problem about date 时间限制:2000 ms  |  内存限制:65535 KB 难度:2   描述 acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你 ...

  9. Laya list 居中

    1.将list放在一个box中,去除box的宽高,设其锚点为0.5,0.5 2.将box的锚点放到目标位置 3.在list渲染后,设定box的宽度为list的宽度

  10. “玲珑杯”ACM比赛 Round #19

    A -- A simple math problem Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 DESCRIPTIO ...