QOJ.ac

QOJ

Limite de temps : 1.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#9537. 中国象棋

Statistiques

这是一个交互式问题。

中国象棋是一种在中国非常流行的双人策略棋盘游戏。中国象棋棋盘共有 10 行 9 列。我们将从下往上第 $r$ 行、从左往右第 $c$ 列的点记为 $(r, c)$ ($0 \le r \le 9, 0 \le c \le 8$)。

本题中有六种棋子:将(King)、士(Mandarin)、车(Rook)、马(Knight)、象(Bishop)和兵(Pawn)。注意,本题不考虑炮。此外,所有棋子都可以移动到棋盘上的任意位置,这与原始规则略有不同。每种棋子的移动规则如下(假设当前位置为 $(r, c)$):

棋子 符号 一步可到达的位置
J $(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)$
S $(r + 1, c + 1), (r + 1, c - 1), (r - 1, c + 1), (r - 1, c - 1)$
C 所有满足 $r' = r$ 或 $c' = c$ 的 $(r', c')$,但不包括 $(r, c)$ 本身
M $(r + 2, c + 1), (r + 2, c - 1), (r - 2, c + 1), (r - 2, c - 1), (r + 1, c + 2), (r + 1, c - 2), (r - 1, c + 2), (r - 1, c - 2)$
X $(r + 2, c + 2), (r + 2, c - 2), (r - 2, c + 2), (r - 2, c - 2)$
B 若 $r \le 4$,则为 $(r + 1, c)$;否则为 $(r + 1, c), (r, c + 1), (r, c - 1)$

当然,棋子不能移出棋盘边界。现在你已经了解了规则,让我们开始游戏。

我在棋盘上放置了一枚棋子,你无法看到它的位置或类型。但我会提供一个包含 $n$ 个可能位置的集合 $A$。你的目标是使用最少的查询次数确定棋子的类型。对于每次查询,你可以选择棋盘上的一个位置,我会告诉你该棋子移动到该位置所需的最少步数,或者告诉你该棋子无法到达该位置。

很有趣,不是吗?更有趣的是,我实际上是在暗中与你博弈。事实上,虽然集合 $A$ 是固定的,但我并没有从一开始就固定这枚棋子的类型和位置。我的策略是调整对你每次查询的回答,以最大化你所需的查询次数,且不与之前给出的信息相矛盾。在双方策略都最优的情况下,你所需的查询次数 $m$ 实际上是可以确定的。我相信你足够聪明,能找出答案。游戏开始!

交互格式

首先,从标准输入读取一个整数 $n$ ($1 \le n \le 90$),表示集合 $A$ 的大小。 然后,读取 $n$ 行。每行包含两个整数 $r$ 和 $c$,表示集合 $A$ 中的一个位置。保证所有位置互不相同。

在读取这 $n+1$ 行后,你应该向标准输出输出一个整数 $m$,表示查询次数。如果你的输出 $m$ 不正确,你将得到 Wrong answer 判决。之后你必须进行恰好 $m$ 次查询。

进行查询时,单行输出 ? r c ($0 \le r \le 9, 0 \le c \le 8$)。然后从标准输入读取一个整数,表示棋子移动到所选位置所需的最少步数,如果棋子无法到达该位置,则返回 $-1$。如果你的程序进行了无效查询或超过了查询次数,交互器将立即终止,你将收到 Wrong answer 判决。

要输出你对棋子类型的猜测,你需要输出 ! ch,其中 ch 表示题目中所示的棋子符号。

在你进行查询或输出答案(包括 $m$ 和棋子类型)后,不要忘记输出换行符 \n 并刷新输出。为此,请使用: C++ 中的 fflush(stdout)cout.flush() Java 中的 System.out.flush(); * Python 中的 stdout.flush()

样例

输入格式 1

1
9 0

输出格式 1

1
? 3 6
! S

说明

对于第一个样例,六种棋子从位置 $(9, 0)$ 移动到 $(3, 6)$ 所需的最少步数如下:

将 (J) 士 (S) 车 (C) 马 (M) 象 (X) 兵 (B)
12 6 2 4 3 -1

因此,你只需要进行一次查询即可确定答案。

输入格式 2

4
2 1
2 3
2 5
2 7

输出格式 2

3
? 0 0
? 2 0
! J

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.