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 ...
随机推荐
- proto_ops和proto区别
**proto_ops:**该结构体包含了某个特定的"protocol family"的一系列functions. 其包含的functions和struct proto很类似,但是 ...
- leetcode刷题——排序
知识点 CS-Notes 备忘-必备算法 题目 冒泡排序 插入排序 归并排序 选择排序 快速排序 希尔排序 堆排序 桶排序 题解 CS-Notes awesome-algorithm
- linux python 安装 pip出现 No module named 'setuptools'
1.下载pip wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#m ...
- 【20】display,float,position的关系
[20]display,float,position的关系 如果display为none,元素不显示. 否则,如果position值为absolute或者fixed,元素绝对定位,float的计算值为 ...
- 爬虫开发python工具包介绍 (4)
本文来自网易云社区 作者:王涛 此处我们给出几个常用的代码例子,包括get,post(json,表单),带证书访问:Get 请求 @gen.coroutine def fetch_url(): ...
- STM32F407 I2C 个人笔记
源代码;https://github.com/YuQiao0303/STM32F407-Examples/tree/master/24.IIC 概述 I2C (IIC, Inter-Integrate ...
- Python第三方库之openpyxl(8)
Python第三方库之openpyxl(8) 饼图 饼图将数据绘制成一个圆片,每个片代表整体的百分比.切片是按顺时针方向绘制的,0在圆的顶部.饼图只能取一组数据.该图表的标题将默认为该系列的标题. 2 ...
- HDU——4549M斐波那契数列(矩阵快速幂+快速幂+费马小定理)
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Su ...
- BZOJ 3926 [Zjoi2015]诸神眷顾的幻想乡 ——广义后缀自动机
神奇的性质,叶子节点不超过20个. 然后把这些节点提出来构成一颗新树,那么这些树恰好包含了所有的情况. 所以直接广义后缀自动机. 然后统计本质不同的字符串就很简单显然了. #include <c ...
- POJ 3581 Sequence ——后缀数组 最小表示法
[题目分析] 一见到题目,就有了一个显而易见obviously的想法.只需要每次找到倒过来最小的那一个字符串翻转就可以了. 然而事情并不是这样的,比如说505023这样一个字符串,如果翻转了成为320 ...