QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100 تفاعلية

#5471. 交互式数字猜谜

الإحصائيات

这是一个交互式问题。

你的任务是编写一个程序,通过重复的询问和响应来猜出一个秘密数字。该秘密数字是一个小于 $10^{18}$ 的非负整数。

设 $x$ 为秘密数字。在一次询问中,你需要指定一个非负整数 $a$。作为响应,系统将返回 $(x + a)$ 的各位数字之和。这里,一个数字的各位数字之和是指其十进制表示中所有数字的总和。例如,$4096$ 的各位数字之和为 $4 + 0 + 9 + 6 = 19$。

交互

你应该从向标准输出发送询问开始,并从标准输入接收响应。此交互可以重复多次。当你通过这些交互确信你的猜测时,你可以发送你的答案。

询问应采用以下格式,并以换行符结尾:

query a

其中,$a$ 是一个 $0$ 到 $10^{18} - 1$ 之间的整数(包含边界)。作为对该询问的响应,$(x + a)$ 的各位数字之和(其中 $x$ 是秘密数字)将被发送回标准输入,并以换行符结尾。

你应该以以下格式向标准输出发送你的答案,并以换行符结尾:

answer y

其中,$y$ 是你确定的秘密数字,为一个 $0$ 到 $10^{18} - 1$ 之间的整数。

你只能发送一次答案,因此在发送答案之前,你必须通过重复的交互确信你的猜测。但是,你最多只能发送 $75$ 次询问,因此你必须明智地选择你的询问。发送答案后,你的程序应立即终止,且不得有任何额外输出。

交互式评测说明

当你的输出违反了上述任何条件(格式无效、$a$ 或 $y$ 超出范围、询问次数过多、发送答案后有额外输出等)时,你的提交将被判为错误答案(Wrong Answer)。由于某些环境需要刷新输出缓冲区,请确保你的输出确实已发送。否则,你的输出将永远无法到达评测系统。

样例

样例 1

query 3
15
query 25
1
answer 75

说明

在此示例中,秘密数字 $x$ 为 $75$。对于第一次询问,返回 $15$,因为 $x + a = 75 + 3 = 78$,其各位数字之和为 $7 + 8 = 15$。在第二次响应之后,你可以断定唯一的可能秘密数字是 $75$。

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.