QOJ.ac

QOJ

Limite de temps : 9 s Limite de mémoire : 1024 MB Points totaux : 100

#515. 一道随机题

Statistiques

生成一个随机数字序列并不容易。许多序列看起来是随机的,但仔细观察后,我们可以发现数字出现时隐藏的规律。例如,考虑以下以 4 7 9... 开头的 100 位“随机”序列:

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

如果你仔细观察,会发现每当一个 4 紧跟着另一个 4 时,其后的第三个值总是 3(我们确信你已经注意到了)。我们将这类特征称为三元相关(triple correlations),并将其表示为 4(1)4(3)3,其中括号内的数字表示括号两侧的每个数字必须相隔多远。更准确地说,一个长度为 $p$ 的数字序列具有 $a(n)b(m)c$ 三元相关,如果:

  1. 任何时候出现一个 $a$,且 $n$ 个位置后跟着一个 $b$,那么 $b$ 之后 $m$ 个位置处总是有一个 $c$,除非 $b$ 的位置距离序列末尾小于 $m-1$。
  2. 任何时候出现一个 $b$,且 $m$ 个位置后跟着一个 $c$,那么 $b$ 之前 $n$ 个位置处总是有一个 $a$,除非 $b$ 的位置距离序列开头小于 $n-1$。
  3. 任何时候出现一个 $a$,且 $n+m$ 个位置后跟着一个 $c$,那么 $a$ 之后 $n$ 个位置处总是有一个 $b$。
  4. 该相关性至少出现 $\lceil p/40 \rceil + 1$ 次,其中 $\lceil x \rceil$ 表示大于或等于 $x$ 的最小整数。

这类相关性通常很难发现,所以我们需要你的帮助。你将获得一个数字序列,并必须在其中搜索三元相关。

输入格式

输入以一个正整数 $p$ ($p \le 1\,000$) 开头,表示序列中随机数字的数量。下一行开始是 $p$ 个数字,以空格分隔,并可能分布在多行中。每行不超过 100 个数字,且不会有空行。

输出格式

如果列表中存在三元相关,则显示 triple correlation a(n)b(m)c found(并填入 $a, b, c, n$ 和 $m$ 的相应值),否则显示 random sequence。如果序列中存在多个三元相关,则显示其第一次出现(由 $a$ 值在序列中第一次出现的位置决定)的那一个。如果仍然平局,选择 $n$ 值较小的那一个;如果仍然平局,则选择 $m$ 值较小的那一个。

样例

样例输入 1

100
4 7 9 5 9 3 5 0 0 1 7 8 5 0 2 6 3 5 4 4
4 6 3 3 2 7 1 8 7 8 7 6 1 1 7 2 5 4 7 2
0 4 4 5 8 3 0 6 9 3 2 6 6 8 5 2 5 1 2 7
2 4 1 0 0 4 9 1 8 7 5 0 4 4 8 4 3 2 6 8
8 5 6 7 0 9 7 0 3 6 1 4 4 1 2 3 2 6 9 9

样例输出 1

triple correlation 4(1)4(3)3 found

样例输入 2

10
1 2 3 1 2 2 1 1 3 0

样例输出 2

random sequence

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.