CF30D.King's Problem?
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
每一位真正的国王在其一生中,都必须征服世界、举办 Codeforces 世界总决赛、在射击馆赢得粉色熊猫玩偶,并巡游整个王国。
科帕国王已经完成了前三件事。现在他只需巡游整个王国即可。王国是一张无限延伸的平面,其上建立了笛卡尔坐标系。每座城市都是该平面上的一个点。王国中共有 n 座城市,分别位于点 (x1,0),(x2,0),…,(xn,0);此外,在点 (xn+1,yn+1) 还有一座城市。
国王从编号为 k 的城市出发。你的任务是为国王规划一条访问所有城市的路线(访问顺序任意),使得总路程长度最小。允许重复访问某座城市。国王可在任意一座城市结束旅程。任意两座城市之间均存在一条直达道路,其长度等于对应两点之间的欧几里得距离。任意两座城市不可能位于同一坐标点。
输入格式
The first line contains two integers n and k (1 ≤ n ≤ 105, 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 106 by absolute value. No two cities coincide.
第一行包含两个整数 n 和 k(1≤n≤105,1≤k≤n+1)—— 城市的数量以及起始城市的编号。
第二行包含 n+1 个数 xi。
第三行包含 yn+1。
所有坐标均为整数,且其绝对值不超过 106。任意两座城市的位置均不重合。
输出格式
Output the minimum possible length of the journey. Your answer must have relative or absolute error less than 10 - 6.
输出旅程的最小可能长度。你的答案必须满足相对或绝对误差小于 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
输入解题思路,AI测评打分。不知道怎么写?