QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100

#12310. 好、坏与丑

Statistics

本题原本应该有一个关于狂野西部的精彩长篇背景故事,但作者没来得及写完,所以请发挥你的想象力!

考虑一条数轴。玩家初始站在位置 $x = p$。在每一轮开始时,你可以说“+”或“-”。之后,玩家会根据你的指令改变位置。更准确地说,如果你说了 $t$(其中 $t \in \{+, -\}$),且玩家当前位于位置 $x$,那么他会移动到位置 $x' = x + d_t$,其中 $d_+$ 和 $d_-$ 是两个整数常量。

你不知道 $p, d_+$ 和 $d_-$ 的确切值,但你知道玩家属于“好人”(Good)、“坏人”(Bad)或“丑人”(Ugly)中的一种(没错,就是这么有想象力!):

  • “好人”玩家满足 $p = m, d_+ = 2, d_- = -1$;
  • “坏人”玩家满足 $p = -m, d_+ = 1, d_- = -2$;
  • “丑人”玩家满足 $p = m$ 或 $p = -m$,且满足 ($d_+ = 1$ 且 $d_- = -1$) 或 ($d_+ = -1$ 且 $d_- = 1$)。

如你所见,玩家的起始位置取决于某个整数常量 $m$ ($1 \le m \le 1000$)……不幸的是,你也不知道 $m$ 的值。

每一轮结束后,玩家会告诉你他现在是否位于 $x = 0$。

事实证明,通过进行若干轮游戏,你可以唯一确定玩家是“好人”、“坏人”还是“丑人”。请在不超过 $30m$ 轮内完成判断。

在每个测试用例中,$m, p, d_+$ 和 $d_-$ 的值均根据上述规则选定。它们在测试过程中是预先固定且不会改变的。

交互

这是一个交互式问题。

如果你想进行一轮游戏,请在单独的一行中打印“+”或“-”。作为响应,你将获得一行输入,如果玩家到达了 $x = 0$ 的位置,则输入为 1,否则输入为 0。

如果你准备好猜测玩家的类型,请打印一行,包含字符“!”、一个空格以及单词“good”、“bad”或“ugly”中的一个。在此之后,你的程序必须终止。

如果在进行了 $30m$ 轮游戏后你仍未给出答案,你的程序将获得“Wrong Answer”的结果。

为了防止输出缓冲,请在打印每一行后刷新输出缓冲区:在 C 或 C++ 中可以使用 fflush(stdout),在 Java 中使用 System.out.flush(),在 Pascal 中使用 flush(output),或者在 Python 中使用 sys.stdout.flush()

样例

输入 1

0
1

输出 1

-
-
! good

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#358EditorialOpen题解jiangly2025-12-14 07:17:17View

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.