CF1361D.Johnny and James
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
James Bond, Johnny's favorite secret agent, has a new mission. There are n enemy bases, each of them is described by its coordinates so that we can think about them as points in the Cartesian plane.
The bases can communicate with each other, sending a signal, which is the ray directed from the chosen point to the origin or in the opposite direction. The exception is the central base, which lies at the origin and can send a signal in any direction.
When some two bases want to communicate, there are two possible scenarios. If they lie on the same line with the origin, one of them can send a signal directly to the other one. Otherwise, the signal is sent from the first base to the central, and then the central sends it to the second base. We denote the distance between two bases as the total Euclidean distance that a signal sent between them has to travel.
Bond can damage all but some k bases, which he can choose arbitrarily. A damaged base can't send or receive the direct signal but still can pass it between two working bases. In particular, James can damage the central base, and the signal can still be sent between any two undamaged bases as before, so the distance between them remains the same. What is the maximal sum of the distances between all pairs of remaining bases that 007 can achieve by damaging exactly n−k of them?
詹姆斯·邦德——约翰尼最喜爱的秘密特工——接到了一项新任务。共有 n 个敌方基地,每个基地由其坐标描述,因此我们可以将它们视为笛卡尔平面上的点。
这些基地之间可以相互通信,发送信号;该信号是一条从选定基地出发、指向原点或反向(即背离原点)的射线。唯一的例外是位于原点的中央基地,它可以朝任意方向发送信号。
当其中两个基地希望通信时,存在两种可能的情形:
- 若这两个基地与原点共线,则其中一个基地可直接向另一个基地发送信号;
- 否则,信号先从第一个基地发送至中央基地,再由中央基地转发至第二个基地。
我们定义两个基地之间的“距离”为信号在二者间传输所经过的总欧几里得距离。
邦德可以摧毁除其中 k 个基地外的所有基地,而这 k 个幸存基地可由他任意选定。被摧毁的基地既不能主动发送也不能直接接收信号,但仍可在两个正常运行的基地之间中继传递信号。特别地,詹姆斯甚至可以摧毁位于原点的中央基地;此时,任意两个未被摧毁的基地之间仍可按前述规则通信(即若共线则直连,否则经中央中转),因此它们之间的距离保持不变。
那么,通过恰好摧毁 n−k 个基地,邦德所能达到的剩余基地两两之间距离之和的最大值是多少?
输入格式
The first line contains two integers n and k (2≤k≤n≤5⋅105) — the total number of bases and number of bases that have to remain, respectively.
Each of the next n lines contains two integers x and y (−109≤x,y≤109), i-th line contains coordinates of the i-th base. You can assume that no two points coincide and that one of them is (0,0).
第一行包含两个整数 n 和 k (2≤k≤n≤5⋅105) —— 分别表示基地的总数和必须保留的基地数量。
接下来的 n 行中,每行包含两个整数 x 和 y (−109≤x,y≤109),其中第 i 行给出第 i 个基地的坐标。你可以假设任意两个点均不重合,且其中有一个点为 (0,0)。
输出格式
You should output one number — the maximal possible sum of distances between all pairs of some k from given bases. Your answer will be accepted if the absolute or relative error is less than 10−6.
你应该输出一个数字——从给定的基地中选出某 k 个基地时,所有点对之间距离之和的最大可能值。若你的答案的绝对误差或相对误差小于 10−6,则该答案将被接受。
输入输出样例
输入#1
6 2 0 0 1 1 2 2 3 3 0 1 0 2
输出#1
6.24264069
输入#2
6 5 0 0 1 1 2 2 3 3 0 1 0 2
输出#2
32.62741700
输入#3
13 10 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 0 -2 0 1 0 2
输出#3
237.00000000
输入#4
10 5 2 2 4 4 3 5 6 10 0 5 0 0 5 0 10 0 0 10 4 7
输出#4
181.52406315
说明/提示
In the first example, in an optimal solution Bond doesn't destroy bases with indices 4 and 6 (marked in orange):

The following picture represents an optimal solution for the second example. These bases are are not destroyed: 2, 3, 4, 5, 6 (marked in orange).

An optimal solution for the third test is visible in the picture. Only bases 3, 4, 5 are destroyed. Again, the not destroyed bases are marked in orange.

在第一个例子中,最优解中邦德没有摧毁编号为 4 和 6 的基地(图中以橙色标出):

下图展示了第二个例子的最优解。未被摧毁的基地编号为:2、3、4、5、6(图中以橙色标出)。

第三个测试用例的最优解如图所示。仅摧毁了编号为 3、4、5 的基地。同样,未被摧毁的基地以橙色标出。

输入解题思路,AI测评打分。不知道怎么写?