QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100

#17160. 多重集方差

Estadísticas

我们有 $n$ 个由整数组成的多重集(multiset)。我们可以通过将输入中的每个多重集完整地选取任意多次(可以为 $0$ 次)来构建一个非空的多重集。

例如,对于输入的多重集 $\{1, 3\}$、$\{1, 2, 2, 3\}$、$\{3, 5\}$,我们可以通过将第一个多重集选取两次,第二个选取一次,第三个不选取,来构建一个多重集 $M = \{1, 3, 1, 3, 1, 2, 2, 3\}$。

我们能得到的构建多重集的最小和最大方差分别是多少?

回想一下,一个多重集 $X = \{x_1, x_2, \dots, x_k\}$ 的均值 $\text{E}(X)$ 和方差 $\text{Var}(X)$ 定义如下:

$$\text{E}(X) = \frac{1}{k} \sum_{i=1}^{k} x_i, \quad \text{Var}(X) = \frac{1}{k} \sum_{i=1}^{k} (x_i - \text{E}(X))^2$$

例如,上述多重集 $M$ 的均值和方差为:

$$\text{E}(M) = \frac{1}{8}(1 + 3 + 1 + 3 + 1 + 2 + 2 + 3) = \frac{16}{8} = 2,$$ $$\text{Var}(M) = \frac{1}{8}((-1)^2 + 1^2 + (-1)^2 + 1^2 + (-1)^2 + 0^2 + 0^2 + 1^2) = \frac{6}{8} = \frac{3}{4}.$$

输入格式

输入的第一行包含一个整数 $t$ ($1 \le t \le 1000$),表示测试用例的数量。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示多重集的数量。

接下来的 $n$ 行描述这些多重集。每行以一个整数 $k$ ($1 \le k \le 10$) 开始,表示该多重集的大小,后面跟着 $k$ 个范围在 $[-2 \cdot 10^5, 2 \cdot 10^5]$ 内的整数,表示该多重集中的元素。

所有测试用例中所有多重集大小的总和不超过 $10^6$。

输出格式

输出恰好 $t$ 行,包含后续测试用例的答案。

答案由两个用空格隔开的实数组成,分别表示最小和最大方差。允许的相对或绝对误差为 $10^{-11}$。也就是说,如果你输出的答案是 $S$,而正确的精确结果是 $R$,则必须满足 $|S - R| \le 10^{-11} \cdot \max(1, R)$。你最多可以输出小数点后 20 位数字。

可以证明,总存在一种方案能达到最小方差,也总存在一种方案能达到最大方差。

样例

输入样例 1

3
3
2 1 3
4 1 2 2 3
2 3 5
2
3 -3 0 0
3 -2 -2 1
2
2 1 3
1 5

输出样例 1

0.5 2
2 2
0 2.777777777778

说明

在第一个测试用例中,最小方差(等于 $\frac{1}{2}$)是通过多重集 $\{1, 2, 2, 3\}$ 达到的,最大方差(等于 $2$)是通过多重集 $\{1, 3, 3, 5\}$ 达到的。

在第二个测试用例中,最小和最大方差(均等于 $2$)都是通过多重集 $\{-3, 0, 0, -2, -2, 1\}$ 达到的。

在第三个测试用例中,最小方差(等于 $0$)是通过多重集 $\{5\}$ 达到的,最大方差(等于 $\frac{25}{9}$)是通过多重集 $\{1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 5, 5, 5, 5, 5, 5, 5\}$ 达到的。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1619EditorialOpen关于 jiangly 题解的一个细节补充xbw_________2026-04-23 21:45:47View
#1059EditorialOpen题解jiangly2026-03-05 16:08:24View

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.