QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 1024 MB 总分: 100

#8043. 中位赛

统计

这是一个交互式问题。

Middle Race 是综艺节目“The Genius”中的一款棋盘游戏。在 Middle Race 中,几名玩家在棋盘上进行比赛,目标是避免获得第一名或最后一名。在本题中,你需要与 BoBo 和 oBoB 进行该游戏的简化版本。

游戏包含 $n$ 个回合。在游戏开始前,会给出三个整数参数 $A, B, C$。每一回合都会提供三个数值分别为 $A, B, C$ 的物品。你、BoBo 和 oBoB 将按顺序从剩余的物品中各取走一个。

设 $X, Y, Z$ 分别为你、BoBo 和 oBoB 在所有回合中取走的物品总价值。当且仅当 $\min(Y, Z) \le X \le \max(Y, Z)$ 时,你赢得游戏。

为了证明你比 BoBo 更聪明,请赢得游戏,或者判断是否存在必胜策略(即如果 BoBo 和 oBoB 采取最优策略,你是否有机会获胜)。

交互

每个测试运行包含多个测试用例。你首先需要读取一个整数 $T$ ($1 \le T \le 10^5$),表示测试用例的数量。

对于每个测试用例,你首先需要读取一行包含整数 $n, A, B, C$ ($1 \le n, A, B, C \le 10^5$),表示游戏的轮数和参数。

如果给定输入下不存在必胜策略,请单独输出 $-1$,然后继续处理下一个测试用例(如果有)。

否则,你需要完成 $n$ 个回合的游戏。在每一回合中,你首先需要输出一行整数 $x \in \{A, B, C\}$,表示你本回合要取走的物品价值。如果你执行了非法操作,你将在下一行读到 $-1\ -1$,此时你必须立即终止程序以获得正确的判决。否则,下一行将给出两个整数 $y, z$,表示 BoBo 在本回合取走了价值为 $y$ 的物品,oBoB 取走了价值为 $z$ 的物品。完成所有 $n$ 个回合后,请继续处理下一个测试用例(如果有)。

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

在输出整数后,请务必输出换行并刷新缓冲区。否则,你可能无法获得正确的判决。刷新缓冲区的方法如下:

  • C/C++ 中使用 fflush(stdout)cout.flush()
  • Java 中使用 System.out.flush()
  • Python 中使用 stdout.flush()

样例

输入 1

2
1 1 1 1
1 1
2 1 3 2
1 3
1 3

输出 1

1
2
2

说明

样例中的空行仅为了方便理解,你的程序中不得输出空行。

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.