QOJ.ac

QOJ

Limite de temps : 10 s - 20 s Limite de mémoire : 1024 MB Points totaux : 25

#5979. 对数集

Statistiques

一个集合 $S$ 的幂集(power set)是 $S$ 的所有子集构成的集合(包括空集和 $S$ 本身)。从集合得到其幂集很容易,但在本题中,我们要反其道而行之!

我们从一个包含(不一定唯一)整数的集合 $S$ 开始,求出它的幂集,然后将幂集中的每个元素替换为该子集中所有元素的和,从而形成一个新的集合 $S'$。例如,如果 $S = \{-1, 1\}$,则 $S$ 的幂集为 $\{\{\}, \{-1\}, \{1\}, \{-1, 1\}\}$,因此 $S' = \{0, -1, 1, 0\}$。$S'$ 允许包含重复元素,因此如果 $S$ 有 $N$ 个元素,则 $S'$ 总是恰好有 $2^N$ 个元素。

给定 $S'$ 中元素的描述及其频率,你能确定原始集合 $S$ 吗?题目保证 $S$ 存在。如果存在多个可能的集合 $S$ 都能产生 $S'$,我们保证原始集合 $S$ 是这些可能性中“最早”的一个。为了确定集合 $S_1$ 是否比另一个相同长度的集合 $S_2$ 更早,需将每个集合按非递减顺序排序,然后检查它们第一个不同的位置。当且仅当 $S_1$ 在该位置的元素小于 $S_2$ 在该位置的元素时,$S_1$ 更早。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例包含一行整数 $P$,随后是两行,每行包含 $P$ 个空格分隔的整数。第一行包含 $S'$ 中出现的所有不同元素 $E_1, E_2, \dots, E_P$,按升序排列。第二行包含每个值在 $S'$ 中出现的次数 $F_1, F_2, \dots, F_P$。也就是说,对于任何 $i$,$E_i$ 在 $S'$ 中出现了 $F_i$ 次。

输出格式

对于每个测试用例,输出一行 "Case #x: ",其中 $x$ 是测试用例编号(从 1 开始),后跟原始集合 $S$ 的元素,以空格分隔,并按非递减顺序排列。(你只需列出 $S$ 的元素,不需要像 $S'$ 那样提供元素和频率的列表。)

数据范围

$1 \le T \le 100$。 $1 \le P \le 10000$。 $F_i \ge 1$。

小数据集(6 分)

$S$ 将包含 1 到 20 个元素。 $0 \le$ 每个 $E_i \le 10^8$。

大数据集(19 分)

$S$ 将包含 1 到 60 个元素。 $-10^{10} \le$ 每个 $E_i \le 10^{10}$。

样例

输入 1

5
8
0 1 2 3 4 5 6 7
1 1 1 1 1 1 1 1
4
0 1 2 3
1 3 3 1
4
0 1 3 4
4 4 4 4
3
-1 0 1
1 2 1
5
-2 -1 0 1 2
1 2 2 2 1

输出 1

Case #1: 1 2 4
Case #2: 1 1 1
Case #3: 0 0 1 3
Case #4: -1 1
Case #5: -2 1 1

说明

注意,Case #4 和 Case #5 不在小数据集的范围内。

在 Case #4 中,$S = \{-1, 1\}$ 是唯一满足条件的集合。(它的子集是 $\emptyset, \{-1\}, \{1\}, \{-1, 1\}$。它们的和分别为 $0, -1, 1, 0$,因此 $S'$ 包含一个 $-1$,两个 $0$,一个 $1$,这与输入中的规格相符。)

对于 Case #5,注意 $S = \{-1, -1, 2\}$ 也会产生相同的 $S' = \{-2, -1, -1, 0, 0, 1, 1, 2\}$,但 $S = \{-2, 1, 1\}$ 比 $\{-1, -1, 2\}$ 更早,因为在第一个不同点上,$-2 < -1$。所以 -1 -1 2 将不是一个可接受的答案。1 -2 1 也是不可接受的,即使它是正确的集合,因为元素没有按非递减顺序排列。

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.