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 ...
随机推荐
- 基础训练 Sine之舞
Sine之舞 #include<iostream> #include<vector> #include<string.h> using namespace std; ...
- luogu2216 [HAOI2007]理想的正方形
先对于每一行中长度为 n 的列用单调队列搞出它们的最小/大值,再将这些长度为 n 的列想象成点再对行跑一遍 #include <iostream> #include <cstring ...
- android 之 View
在进行游戏开发时,需要自定义各种控件和界面. 自定义View的使用: 绘制屏幕 刷新屏幕:后台数据发生了变化,需要开发人员自己刷新屏幕以显示最新数据 例子: MyView开发,绘制界面View内容: ...
- 【LeetCode】Available Captures for Rook(车的可用捕获量)
这道题是LeetCode里的第999道题. 题目叙述: 在一个 8 x 8 的棋盘上,有一个白色车(rook).也可能有空方块,白色的象(bishop)和黑色的卒(pawn).它们分别以字符 &quo ...
- A. Test for Job
A. Test for Job Time Limit: 5000ms Case Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO ...
- matalb sum函数和sum变量的用法
在对矩阵或者向量求和要用到sum函数的时候代码里面千万不要出现将sum作为变量名
- CodeForces contest/776 A+B+C题解
ICM Technex 2017 and Codeforces Round #400 (Div. 1 +Div.2,combined) A. A Serial Killer 谜一样的题意:每天从两个人 ...
- 如何部署 sources and javadoc jars
mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file -Durl=file:///home/me/m2-repo \ - ...
- Android隐藏软键盘收回软键盘
代码改变世界 Android隐藏软键盘收回软键盘 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPU ...
- Ubuntu安装 Docker CE,VNC访问docker图形界面并安装ROS
从包安装 如果您无法使用Docker的存储库来安装Docker CE,则可以下载.deb适用于您的发行版的 文件并手动安装.每次要升级Docker CE时都需要下载新文件. 安装Docker CE,将 ...