QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#11251. 天才琪露诺的天才计算机

Statistics

这是一个交互式问题。

在 9999 年,天才冰之妖精琪露诺制造了超级计算机 Cirno9,它能够进行 1024 位整数运算(int1024)!然而,因为琪露诺是个天才,这台机器只支持整数运算。Cirno9 拥有 8 个通用寄存器(变量),命名为 $a, b, c, d, r_0, r_1, r_2, r_3$。

作为一名来自 2025 年的时光旅行者,你获得了临时的访问权限。Cirno9 的前四个寄存器 $a, b, c, d$ 被初始化为四个可以用 int1024 表示的正整数 $a_0, b_0, c_0, d_0$,而其他四个寄存器 $r_0 \dots r_3$ 被初始化为 0。你的任务是使用 Cirno9 来比较分数 $\frac{a_0}{b_0}$ 和 $\frac{c_0}{d_0}$ 的大小。

你无法直接观察 $a_0, b_0, c_0, d_0$ 的值,但你可以向 Cirno9 发送最多 6666 次操作请求,并根据其响应做出判断。详情请参阅下文的“交互协议”部分。

在琪露诺发布“完美冻结”之前完成这项任务!

补充说明

由于你来自一个只有 int32int64(或许还有 int128)的时代,以下是关于 Cirno9 的 int1024 的额外细节:

  • int1024 运算的行为类似于 C/C++ 的 int 运算,支持加法、减法、乘法、除法(+, -, *, /)和比较。与 C/C++ 一样,整数除法向零取整。例如:$100/3 = 33$, $(-5)/2 = -2$, $(-10)/(-3) = 3$。
  • int1024 可以表示 $[-2^{1023}, 2^{1023})$ 范围内的整数。运算不得溢出——结果必须能用 int1024 表示,否则 Cirno9 将会爆炸。对于除法,除数不能为 0,否则 Cirno9 将会冻结。

输入格式

没有初始输入。你必须向交互器发送查询。

交互协议

你可以使用 8 个名为 $a, b, c, d, r_0, r_1, r_2, r_3$ 的 int1024 变量(对应的字符串为:a b c d r0 r1 r2 r3)。

  • $a, b, c, d$ 初始化为正整数 $a_0, b_0, c_0, d_0$
  • $r_0, r_1, r_2, r_3$ 初始化为 0

你可以执行以下操作:

  1. op x y z:计算 $y \text{ op } z$ 并将其存储在 $x$ 中($\text{op} \in \{+, -, *, /\}$)
    • 如果成功,返回 ok,否则返回 err
  2. ? x y:比较 $x$ 和 $y$
    • 返回 >, =, 或 < 表示它们的关系,如果失败则返回 err
  3. ! rel:提交 $\frac{a_0}{b_0}$ 和 $\frac{c_0}{d_0}$ 的最终比较结果($\text{rel} \in \{>, =, <\}$)
    • 如果正确,返回 ok,否则返回 err

注意:对于操作类型 1 和 2,变量名可以相同(例如,“+ a a b” 或 “* r0 r0 r0”)。

err 响应的可能原因: 1. 无效操作 2. 变量不存在 3. 算术溢出或除以零 4. 超过操作限制 5. 最终答案错误

当收到 err 时,你的程序将被判为 Wrong Answer。你应该在读取 err 后立即终止程序,以避免意外的评测结果。

你最多可以执行 6666 次操作。最终答案不计入此限制;其他操作每次计为 1 次。

打印操作后,请务必输出换行符并刷新输出。否则你将收到 Time Limit Exceeded。刷新方法: C++: fflush(stdout)cout.flush() Pascal: flush(output) Java: System.out.flush() Python: stdout.flush()

样例

输入 输出
* r0 a d
ok
* r1 b c
ok
- r0 r0 r1
ok
? r0 r2
>
! >
ok

说明

在此样例中,交互器内部的初始值为 $a = 99, b = 999, c = 9, d = 99$。我们需要比较 $\frac{99}{999}$ 和 $\frac{9}{99}$ 的大小。

  1. 操作 1:* r0 a d
    • 计算 $a \times d = 99 \times 99 = 9801$,并将结果存储在 $r_0$ 中。
    • 交互器返回 ok,表示操作成功。
  2. 操作 2:* r1 b c
    • 计算 $b \times c = 999 \times 9 = 8991$,并将结果存储在 $r_1$ 中。
    • 交互器返回 ok,表示操作成功。
  3. 操作 3:- r0 r0 r1
    • 计算 $r_0 - r_1 = 9801 - 8991 = 810$,并将结果存储在 $r_0$ 中。
    • 交互器返回 ok,表示操作成功。
  4. 操作 4:? r0 r2
    • 比较 $r_0$ 和 $r_2$ 的值。由于 $r_0 = 810$ 且 $r_2 = 0$,我们有 $r_0 > r_2$。
    • 交互器返回 >
  5. 操作 5:! >
    • 我们知道 $\frac{a_0}{b_0} = \frac{99}{999} \approx 0.0991$,且 $\frac{c_0}{d_0} = \frac{9}{99} \approx 0.0909$,因此报告的答案是正确的。
    • 交互器返回 ok,表示答案正确。

附件提供了 Cirno9 的参考实现,你可以用它来测试 int1024

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.