QOJ.ac

QOJ

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

#15356. 传纸条

Estadísticas

这是一个通信题。

Bob 和 Alice 玩了 $n$ 次猜数游戏。每次在正确猜出 Alice 心中所想的数字后,Bob 都会在便签上写下一个长度为 8 的 01 字符串来记录该数字,总共会产生 $n$ 张便签。

然而,如果便签被翻转了,记录的 01 字符串也会随之反转(即左右颠倒),从而无法确定该字符串应该从左往右读还是从右往左读。为了避免歧义,Bob 必须设计一种编码和解码方案,使得无论便签是否被翻转,都能从便签上的信息中唯一地恢复出原始数字。

一段时间后,Bob 重新找到了这 $n$ 张便签,他需要根据便签上的信息恢复出记录的数字。

对于每个测试用例,你的程序将运行两次:

  • 第一次运行:Bob 和 Alice 玩了 $n$ 次猜数游戏。每次在正确猜出 Alice 心中所想的数字后,他通过在便签上写下一个长度为 8 的 01 字符串来记录该数字。
  • 第二次运行:Bob 重新找到了这 $n$ 张便签,并需要根据便签上的信息恢复出记录的数字。这些便签正是第一次运行期间记录的那些。每张便签可能被翻转了(即其 01 字符串可能被反转了),并且便签的顺序可能被打乱了。此外,第二次运行不会从第一次运行中获得任何额外的信息。如果你的程序正确恢复了便签上记录的所有数字,则通过该测试用例。

输入格式

输入的第一行包含两个整数 $op$ ($op \in \{1, 2\}$) 和 $n$ ($1 \le n \le 100$),分别表示程序的运行次数编号和便签的数量。保证两次运行之间的 $n$ 保持一致。

如果 $op = 1$,你的程序需要写便签来记录数字。接下来的 $n$ 行,每行包含一个整数 $x$ ($0 \le x \le 100$),表示需要记录的数字。

如果 $op = 2$,你的程序需要恢复便签上记录的数字。接下来的 $n$ 行,每行包含一个长度为 8 的 01 字符串,表示便签上的信息。这 $n$ 个 01 字符串将以任意顺序给出,不一定与第一次运行中给出的数字顺序相对应。

输出格式

如果 $op = 1$,输出 $n$ 行,每行包含一个长度为 8 的 01 字符串,表示记录在便签上的信息。

如果 $op = 2$,输出 $n$ 行。对于输入中给出的每个 $n$ 个 01 字符串,输出一行包含一个整数,表示从便签信息中恢复出的数字。

样例

输入样例 1

1 2
0
100

输出样例 1

00000000
00001111

输入样例 2

2 2
00001111
00000000

输出样例 2

100
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.