QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 互動

#10029. 永恒大师

统计

这是一个交互式问题。

两名玩家,Red 和 White,根据以下规则进行游戏(灵感来源于“万智牌”规则):

  • White 拥有 $L$ 点生命值;$L$ 是一个正整数。
  • Red 的目标是将 $L$ 降低到 0 或以下。White 的目标是防止这种情况发生。
  • Red 手中有 $n$ 张牌。第 $i$ 张牌可以将 $L$ 减少一个正整数 $r_i$。
  • White 手中有 $m$ 张牌。第 $i$ 张牌可以将 $L$ 增加一个正整数 $w_i$。
  • 每张牌从手中打出后最多只能使用一次。
  • 玩家了解对方手中的牌。
  • Red 和 White 轮流行动;第一回合是 Red 的回合。
  • 在每一回合,轮到行动的玩家可以选择从手中打出一张牌(如果有的话)或者选择“pass”(跳过)。
  • 存在一个名为“堆叠”(stack)的区域,类似于程序员的栈。初始时堆叠为空。从手中打出一张牌不会立即触发其效果。相反,它会导致该牌被放置在堆叠的顶部。堆叠由两名玩家共享。
  • “pass”会导致堆叠顶部的牌(我们可以证明,这总是对手的牌)触发其效果。然后该牌从堆叠中移除并被弃置。
  • 如果 White 的“pass”导致 $L$ 变为 0 或更低,White 立即输掉比赛。
  • 如果 Red 在堆叠为空时“pass”,Red 立即输掉比赛。
  • 可以证明,每一局游戏最终都会以上述两种方式之一结束。

给定 $L, n, r, m$ 和 $w$,选择一名玩家并代表该玩家与交互器对战以取得胜利。

交互

交互从读取给定的游戏状态开始。

第一行包含一个整数 $n$ ($1 \le n \le 1000$):Red 手中的牌数。接下来的 $n$ 行包含 $n$ 个整数 $r_1, r_2, \dots, r_n$ ($1 \le r_i \le 10^6$):Red 手中牌的数值,每行一个。

下一行包含一个整数 $m$ ($1 \le m \le 1000$):White 手中的牌数。接下来的 $m$ 行包含 $m$ 个整数 $w_1, w_2, \dots, w_m$ ($1 \le w_i \le 10^6$):White 手中牌的数值,每行一个。

不同的牌可能具有相同的数值。

下一行包含一个整数 $L$ ($1 \le L \le 10^6$):初始生命值。

读取所有这些值后,打印一行,内容为“Red”或“White”。这表示你将要扮演的玩家。

之后,游戏从 Red 的回合开始。

在你的回合,如果你想“pass”,打印“pass”。如果你想从手中打出一张牌,打印“play x”,其中 $x$ 是你想打出的牌的数值;该牌必须是你当前可用的。

在交互器的回合,读取一行。该行内容为“pass”或“play x”,其中 $x$ 是交互器从手中打出的牌的数值。

如果交互器的“pass”导致你获胜,你的程序应打印“win”并正常终止。

如果你的“pass”导致你输掉比赛,交互器将打印“win”。读取该行后,正常终止你的程序以获得“Wrong Answer”判决。

打印内容后,不要忘记输出换行符并刷新输出。否则,你将获得“Idleness limit exceeded”判决。刷新输出的方法如下:

  • C++ 中使用 fflush(stdout)cout.flush()
  • Java 中使用 System.out.flush()
  • Pascal 中使用 flush(output)
  • Python 中使用 stdout.flush()
  • 其他语言请参阅相关文档。

样例

输入 1

3
6
2
2
1
9
6
play 2
play 2
play 6
pass
pass

输出 1

White
pass
pass
play 9
pass
win

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.