QOJ.ac

QOJ

Límite de tiempo: 20 s Límite de memoria: 1024 MB Puntuación total: 29

#12425. 指数博弈

Estadísticas

你刚刚收到了有史以来最好的礼物:一根 Expogo 跳杆。你可以站在上面,利用它进行越来越大的跳跃。

你目前站在无限二维后院的点 $(0, 0)$ 上,目标是以尽可能少的跳跃次数到达目标点 $(X, Y)$(坐标为整数)。你必须准确地落在目标点上;仅仅在跳跃过程中经过它是不够的。

每次使用 Expogo 跳杆跳跃时,你需要选择一个基准方向:北、南、东或西。第 $i$ 次跳跃会使你沿选定方向移动 $2^{(i-1)}$ 个单位,因此第一次跳跃移动 1 个单位,第二次跳跃移动 2 个单位,第三次跳跃移动 4 个单位,依此类推。

给定目标点 $(X, Y)$,确定是否可以到达该点,如果可以,请演示如何以最少的跳跃次数完成。

输入格式

输入的第一行包含测试用例的数量 $T$。接下来是 $T$ 个测试用例。每个测试用例由一行组成,包含两个整数 $X$ 和 $Y$:目标点的坐标。

输出格式

对于每个测试用例,输出一行 Case #x: y,其中 $x$ 是测试用例编号(从 1 开始),如果无法到达目标点,则 $y$ 为 IMPOSSIBLE。否则,$y$ 必须是一个由一个或多个字符组成的字符串,每个字符为 N(北)、S(南)、E(东)或 W(西),按顺序表示你将要进行的跳跃方向。此跳跃序列必须在最后一次跳跃结束时到达目标点,且长度必须尽可能短。

数据范围

$(X, Y) \neq (0, 0)$。

测试集 1 $1 \le T \le 80$ $-4 \le X \le 4$ $-4 \le Y \le 4$

测试集 2 $1 \le T \le 100$ $-100 \le X \le 100$ $-100 \le Y \le 100$

测试集 3 $1 \le T \le 100$ $-10^9 \le X \le 10^9$ $-10^9 \le Y \le 10^9$

样例

样例输入 1

4
2 3
-2 -3
3 0
-1 1

样例输出 1

Case #1: SEN
Case #2: NWS
Case #3: EE
Case #4: IMPOSSIBLE

说明

在样例 1 中,你可以从 $(0, 0)$ 向南跳到 $(0, -1)$,然后向东跳到 $(2, -1)$,最后向北跳到 $(2, 3)$。

我们可以确定不存在更高效的解法(两次或更少跳跃),因为到达目标点至少需要 $2 + 3 = 5$ 个单位的距离,而前两次跳跃总共只能提供 3 个单位的距离。

注意,样例 2 类似于样例 1,但关于两个轴进行了对称,因此答案可以通过将样例 1 答案中的所有方向进行对称变换得到。

在样例 3 中,注意 EWE 虽然能到达目标,但不是有效答案,因为存在跳跃次数更少的路径。

我们留给你自己去判断为什么样例 4 中无法到达目标。

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.