QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 22

#5776. 代码序列

Statistics

你需要计算由一个秘密代码生成的序列 $S_n$ 的下一个数字。已知该代码是按照以下过程生成的:

首先,对于每个 $0$ 到 $29$ 之间的 $k$,选择一个 $0$ 到 $10006$(含)之间的数字 $C_k$。

然后,对于每个 $0$ 到 $1\,000\,000\,000$(含)之间的整数 $n$:

  • 将 $n$ 写成二进制形式。
  • 对于 $n$ 的二进制表示中所有置位的位 $k$,取出对应的数字 $C_k$。例如,当 $n=5$ 时,第 $0$ 位和第 $2$ 位被置位,因此取出 $C_0$ 和 $C_2$。
  • 将这些 $C_k$ 相加,除以 $10007$,并将余数作为 $S_n$ 输出。

你将获得序列 $S$ 的一系列连续值,但你不知道这些数字在序列中的起始位置(尽管你知道序列中至少还有一个数字),也不知道生成序列时选择了哪些 $C_k$ 值。

找出序列中的下一个数字,如果无法根据输入数据确定,则输出 UNKNOWN。

输入格式

第一行包含一个整数 $T$,表示输入文件中的测试用例数量。

对于每个测试用例:

  • 一行包含整数 $N$,表示你拥有的序列 $S$ 的元素个数。
  • 一行包含 $N$ 个用空格分隔的整数,范围在 $0$ 到 $10006$ 之间,表示序列的已知元素。

输出格式

对于每个测试用例,输出一行 "Case #$X$: $Y$",其中 $X$ 是测试用例编号(从 $1$ 开始),$Y$ 是序列中的下一个数字,如果无法确定下一个数字,则输出字符串 UNKNOWN。

数据范围

$1 \le T \le 20$

小数据集(测试集 1 - 可见;7 分)

$1 \le N \le 5$

大数据集(测试集 2 - 隐藏;15 分)

$1 \le N \le 1000$

样例

样例输入 1

3
7
1 2 3 4 5 6 7
4
1 10 11 200
4
1000 1520 7520 7521

样例输出 1

Case #1: UNKNOWN
Case #2: 201
Case #3: 3514

说明

在第一个案例中,$C_0, C_1$ 和 $C_2$ 可能分别是 $1, 2$ 和 $4$,且我们拥有的 $S_n$ 值是从 $n=1$ 开始的。如果这是正确的,我们不知道 $C_3$,因此序列中的下一个数字可能是任何值!因此答案是 UNKNOWN。

在第二个案例中,我们无法知道所有的 $C_k$ 值,甚至不知道 $n$ 是多少,但我们可以证明在任何序列中,如果 $1, 10, 11, 200$ 按顺序出现,那么下一个值总是 $201$。

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.