A7966 | King's Problem?
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Every true king during his life must conquer the world, hold the Codeforces world finals, win pink panda in the shooting gallery and travel all over his kingdom.
King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordinate system on it. Every city is a point on this plane. There are $n$ cities in the kingdom at points with coordinates $(x_{1},0),(x_{2},0),...,(x_{n},0)$ , and there is one city at point $(x_{n+1},y_{n+1})$ .
King starts his journey in the city number $k$ . Your task is to find such route for the king, which visits all cities (in any order) and has minimum possible length. It is allowed to visit a city twice. The king can end his journey in any city. Between any pair of cities there is a direct road with length equal to the distance between the corresponding points. No two cities may be located at the same point.
King Copa has already done the first three things. Now he just needs to travel all over the kingdom. The kingdom is an infinite plane with Cartesian coordinate system on it. Every city is a point on this plane. There are $n$ cities in the kingdom at points with coordinates $(x_{1},0),(x_{2},0),...,(x_{n},0)$ , and there is one city at point $(x_{n+1},y_{n+1})$ .
King starts his journey in the city number $k$ . Your task is to find such route for the king, which visits all cities (in any order) and has minimum possible length. It is allowed to visit a city twice. The king can end his journey in any city. Between any pair of cities there is a direct road with length equal to the distance between the corresponding points. No two cities may be located at the same point.
输入格式
The first line contains two integers $n$ and $k$ ( $1<=n<=10^{5},1<=k<=n+1$ ) — amount of cities and index of the starting city. The second line contains $n+1$ numbers $x_{i}$ . The third line contains $y_{n+1}$ . All coordinates are integers and do not exceed $10^{6}$ by absolute value. No two cities coincide.
输出格式
Output the minimum possible length of the journey. Your answer must have relative or absolute error less than $10^{-6}$ .
输入输出样例
输入 #1
3 1 0 1 2 1 1
输出 #1
3.41421356237309490000
输入 #2
3 1 1 0 2 1 1
输出 #2
3.82842712474619030000
输入 #3
4 5 0 5 -1 -5 2 3
输出 #3
14.24264068711928400000
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted