QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#11202. 替罪羊树

统计

Aori 非常粗心,所以她总是惹麻烦。有一天她又惹了 $N$ 个大麻烦!但这一次她似乎很从容,因为她找到了 $M$ 个 Inkling 来承担所有的责备。每个麻烦都可以用一个严重程度数值 $a_i$ 来衡量。每个麻烦至少需要一个 Inkling 来承担责备,且每个 Inkling 只能帮 Aori 承担恰好一个麻烦的责备。如果两个或更多的 Inkling 承担同一个麻烦,他们将共同承担这份责备,并商量如何将这个麻烦拆分成……一些琐碎的小事……以减轻每个 Inkling 的压力,只要 Inkling 承担的总严重程度等于该麻烦的严重程度即可。

Inkling 们非常热心,所以 Aori 想找到一种方法,使得每个 Inkling 承担的严重程度的方差最小。你能帮 Aori 安排她的替罪羊吗?

形式上,变量的方差是变量与其平均值之差的平方的期望:

$$\sigma^2 = \frac{1}{n} \sum (x_i - \frac{1}{n} \sum x_j)^2$$

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。 对于每个测试用例,第一行包含两个整数 $N$ 和 $M$,其中 $N$ 是麻烦的数量,$M$ 是 Inkling 的数量。下一行包含 $N$ 个整数 $a_1, a_2, \dots, a_N$,表示 Aori 制造的麻烦的严重程度。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是最小方差。 如果 $y$ 与正确答案的绝对误差或相对误差在 $10^{-8}$ 以内,则被视为正确。

数据范围

  • $1 \le T \le 100$
  • $1 \le N \le M \le 2 \times 10^5$
  • $1 \le a_i \le 10000$
  • $\sum M \le 3 \times 10^6$

样例

输入 1

3
3 6
1 2 3
5 10
5 6 7 8 9
6 6
1 1 4 5 1 4

输出 1

Case #1: 0.000000000000
Case #2: 0.400000000000
Case #3: 2.888888888889

说明

对于第一个样例,Aori 可以让一个 Inkling 承担第一个麻烦的责备,两个 Inkling 承担第二个,三个 Inkling 承担第三个。每个 Inkling 承担的严重程度均为 1 单位,因此它们的方差应为 0。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.