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. CSS3的border-image

    border-image:none|image-url|number|percentage|stretch,repeat,round 参数: none:默认,无背景图片 url:地址,可以为绝对,也可 ...

  2. fshc之请求仲裁机制(from mcu and cache)

    1.arbiter模块本身放在sclk时钟域,但是输入都是来之HCLK时钟域. 2.当MCU/CACHE访问FSHC时,FSHC不接受其他请求,FSHC只可以同时处理一个请求的操作. 3.如果原子操作 ...

  3. Python的第3堂课

    20181119笔记 一.内存管理相关 ①Cpython解释器的垃圾回收机制 什么是垃圾:当一个值没有被绑定任何变量名(即该值的引用计数为零时),该值就是垃圾. 垃圾回收是收回值占用的内存空间. 引用 ...

  4. poj 1502

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12087   Accepted: 7464 De ...

  5. JavaScript正则表达式-重复次数(数量词)

    *:表示对前面表达式的匹配出现零次或多次. var reg_pattern = /bo*/;//匹配b.bo.boooo +:表示对前面表达式的匹配连续出现一次或多次. var reg_pattern ...

  6. Django中的csrf相关装饰器

    切记:  这俩个装饰器不能直接加在类中函数的上方 (CBV方式) csrf_exempt除了,csrf_protect受保护的   from django.views import Viewfrom ...

  7. 【02】[].slice和Array.prototype.slice

    [02][].slice和Array.prototype.slice 01,Array是一个构造函数.浏览器内置的特殊对象.   02,Array没有slice方法. 03,Array.prototy ...

  8. luogu3809 后缀排序 后缀数组

    ref and 挑战程序设计竞赛. 主要是发现自己以前写得代码太难看而且忘光了,而且我字符串死活学不会啊,kmp这种东西我都觉得是省选+难度啊QAQ #include <iostream> ...

  9. layer2-1 二层

    一   概述    一层的相关介绍 CSMA/CD 网桥和交换机的区别 冲突    共享      端口密度     性能   功能   交换机的三种主流转发方式 存储转发         完整的收到 ...

  10. 树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains

    C. Fountains time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...