QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 512 MB Puntuación total: 70

#12052. 位元

Estadísticas

先有鸡还是先有蛋?活一百岁当百万富翁好,还是在贫困中度过七天好?如何成为国际象棋特级大师?如何加盲注?如何通过期末考试?如何训练一条龙?这些都是我们只能在比赛结束后思考的有趣问题,但现在我们提供一个不那么有趣的计算机科学问题。

给定两个大小为 $N$ 的数字集合 $A$ 和 $B$。在一次操作中,你可以选择集合 $A$ 中的任意一个元素,并改变其二进制表示中的任意一个数字(位)。改变后的数字在操作前不能是集合 $A$ 中的元素。

例如,数字 $5$ 的二进制表示为 $0101_2$。在一次操作中,如果分别改变其第 4、3、2 或 1 位,它可以变为 $13 = 1101_2$、$1 = 0001_2$、$7 = 0111_2$ 或 $4 = 0100_2$。

确定一个操作序列,使得集合 $A$ 最终等于集合 $B$。如果两个集合大小相同,且集合 $A$ 中不存在不属于集合 $B$ 的元素,则称这两个集合相等。

注意:操作次数不必是最少的,但必须满足题目限制。

输入格式

第一行包含整数 $N$ ($1 \le N \le 2^{15}$),表示集合 $A$ 和 $B$ 的大小。 第二行包含 $N$ 个不同的整数 $a_i$ ($0 \le a_i < 2^{15}$),表示集合 $A$ 中的元素。 第三行包含 $N$ 个不同的整数 $b_i$ ($0 \le b_i < 2^{15}$),表示集合 $B$ 中的元素。

输出格式

第一行输出所需的操作次数。 在接下来的行中,输出数字 $x$ 和 $y$ ($0 \le x, y < 2^{15}$) —— 表示我们将集合 $A$ 中的数字 $x$ 变为数字 $y$。数字 $x$ 和 $y$ 必须恰好相差一位,且在执行操作时,$x \in A$ 且 $y \notin A$ 必须成立。

子任务

在所有子任务中,允许的操作次数不得超过 $2^{19}$。可以证明,在给定的限制条件下,解总是存在的。

子任务 分值 数据范围
1 10 $a_i, b_i \le 2^{14}$
2 15 $N \le 7$
3 30 $N \le 2^7$
4 15 无额外限制

样例

输入 1

3
0 1 2
1 2 3

输出 1

2
1 3
0 1

说明 1

如果先执行操作 $0 \to 1$,然后执行 $1 \to 3$,在这两次操作之间,集合 $A$ 会有两个相同的元素,这是题目所不允许的。另一个可能的解是 $2 \to 3$,$0 \to 2$。

输入 2

3
4 8 31
0 4 8

输出 2

5
31 30
30 28
28 24
24 16
16 0

说明 2

$31 = 11111_2$。通过从低位到高位依次移除位,我们依次得到数字 $30, 28, 24, 16$ 和 $0$。在所有操作完成后,集合 $A$ 变得与集合 $B$ 相等。

输入 3

5
0 1 2 4 5
7 6 5 3 2

输出 3

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

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.