QOJ.ac

QOJ

时间限制: 2 s 内存限制: 256 MB 总分: 100

#5043. 游戏

统计

Alice 和 Bob 正在玩陆战棋。他们每个人都拥有一组包含以下 24 枚棋子的排列:

  • 一枚司令,等级 9
  • 一枚军长,等级 8
  • 两枚师长,等级 7
  • 两枚旅长,等级 6
  • 两枚团长,等级 5
  • 两枚营长,等级 4
  • 三枚连长,等级 3
  • 三枚排长,等级 2
  • 三枚工兵,等级 1
  • 两枚炸弹
  • 三枚地雷

为了决定胜负,我们重复以下过程,直到有人获胜或游戏以平局结束:

  • 如果双方的排列都为空,游戏以平局结束。
  • 如果 Alice 的排列为空,Bob 获胜。
  • 如果 Bob 的排列为空,Alice 获胜。
  • 令 Alice 排列中的第一枚棋子为 $A$,Bob 排列中的第一枚棋子为 $B$。$A$ 和 $B$ 之间的战斗结果如下:
    1. 如果 $A$ 和 $B$ 是相同类型的棋子,或者其中一个是炸弹,则两者都被移除。
    2. 否则,如果其中一个是地雷,另一个是工兵,则地雷被移除,工兵存活。
    3. 否则,如果其中一个是地雷,另一个的等级大于 1,则地雷存活,另一个被移除。
    4. 否则,比较 $A$ 和 $B$ 的等级,等级较小的棋子被移除。

Bob 事先知道 Alice 的排列,并可以据此决定自己的排列。在 Bob 确定其排列后,Alice 可以交换 Bob 排列中的任意两枚棋子。Bob 能否构造出一个排列,使得无论 Alice 交换哪两枚棋子,他都能战胜 Alice 的排列?

输入格式

第一行包含一个整数 $T$,表示测试用例的数量 ($1 \le T \le 100$)。 接下来的 $T$ 行,每行包含 24 个整数,表示 Alice 的排列:

  • 40 代表司令
  • 39 代表军长
  • 38 代表师长
  • 37 代表旅长
  • 36 代表团长
  • 35 代表营长
  • 34 代表连长
  • 33 代表排长
  • 32 代表工兵
  • 31 代表地雷
  • 30 代表炸弹

保证所有排列都是随机均匀选择的,且恰好包含题目描述中的 24 枚棋子。

输出格式

为每个测试用例输出一行。 如果 Bob 无法构造出所需的排列,输出 $-1$。 否则,输出 24 个整数,表示 Bob 的排列,格式与输入相同。如果有多种解,输出任意一种即可。Bob 的排列必须恰好包含题目描述中的 24 枚棋子。

样例

输入 1

4
40 39 38 38 37 37 36 36 35 35 34 34 34 33 33 33 32 32 32 31 31 31 30 30
34 31 36 33 31 39 37 38 35 32 32 35 36 31 34 32 38 40 30 33 30 34 33 37
37 30 40 38 36 38 32 34 36 35 37 32 34 33 31 30 33 31 35 34 33 39 31 32
30 33 32 39 37 38 35 40 34 30 31 37 31 33 31 33 34 32 36 36 35 34 32 38

输出 1

34 36 30 39 33 38 37 31 34 30 33 35 38 31 37 33 40 31 35 32 32 36 32 34
34 32 32 38 40 33 33 30 31 34 31 35 37 32 34 36 33 31 38 30 36 37 35 39
38 33 32 31 36 34 30 34 33 40 32 37 38 30 37 35 33 35 32 31 34 31 39 36
37 34 33 36 34 35 31 38 32 38 31 32 37 30 30 31 33 36 32 33 40 39 34 35

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.