QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#9176. 非交互式 Nim

统计

Nim 是一个经典的两人策略游戏。游戏中有 $n$ 堆石子,第 $i$ 堆包含 $a_i$ 个石子。玩家轮流进行操作。在每一回合中,玩家必须选择一个包含正整数个石子的堆,并从中移除正整数个石子。无法进行操作的玩家即为输。

Blue Monster 想要在“普通与常见问题集”中加入一个交互式的 Nim 问题。在这个问题中,你的程序需要与一个总是采取最优策略的对手进行 Nim 游戏。然而,Blue Monster 太懒了,不想学习如何创建交互式问题。因此,你只需要做出那些使得对手只有唯一一种最优解的操作。

给定 $a_1, a_2, \dots, a_n$ —— 一个 Nim 游戏的实例。保证如果双方都采取最优策略,先手必败。你将作为先手,你的对手作为后手。你的对手总是会采取最优策略。你需要以这样一种方式进行游戏:在你完成每一次操作后,对手只有唯一一种最优操作,且在该操作之后,如果双方继续采取最优策略,你将输掉比赛。

输出这样的一系列操作,或者声明这是不可能的。注意,由于你的对手总是采取最优策略,你确切地知道对手会做出什么操作。你不需要最小化操作序列的长度。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 5 \cdot 10^4$) —— 测试用例的数量。接下来是 $t$ 个测试用例。每个测试用例的描述如下:

第一行包含一个整数 $n$ ($2 \le n \le 10^5$)。第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{18}$)。保证如果双方都采取最优策略,先手必败。

保证所有测试用例的 $n$ 之和不超过 $10^5$。

输出格式

对于每个测试用例,按以下方式输出答案:

如果无法以“对手总是只有唯一一种最优操作”的方式进行游戏,输出 $-1$。

否则,在第一行输出一个整数 $k$ ($1 \le k \le 100$) —— 操作次数。在接下来的 $k$ 行中,每行输出两个整数 $p$ ($1 \le p \le n$) 和 $x$,表示你将从第 $p$ 堆中移除 $x$ 个石子。

可以证明,在本问题的约束条件下,如果存在一种方式使得对手总是只有唯一一种最优操作,那么一定可以在 100 次操作内完成游戏并输掉比赛。

样例

样例输入 1

2
4
4 2 7 1
4
1 1 1 1

样例输出 1

4
3 2
1 2
3 3
4 1
-1

说明

在第一个样例测试中,对手被迫做出操作 $(2, 2)$、$(3, 2)$、$(1, 1)$ 和 $(1, 1)$。游戏过程如下:

你的操作后 对手操作后
4, 2, 5, 1
4, 0, 5, 1
2, 0, 5, 1
2, 0, 3, 1
2, 0, 0, 1
1, 0, 0, 1
1, 0, 0, 0
0, 0, 0, 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.