QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100 Interactive

#11479. Skarb

统计

Bitek 发现了一个宝藏——一个装有一定数量正整数硬币 $x$ 的箱子。Bajtosia 根据箱子的尺寸,巧妙地推断出箱子里的硬币数量肯定不超过 $n$。她想准确地知道硬币的数量。Bitek 不想直接告诉她,但他同意和她玩一个游戏。Bajtosia 可以给他一个正整数 $m$,他会回答以下两个问题之一: 箱子里硬币数量除以 $m$ 的商是多少? 箱子里硬币数量除以 $m$ 的余数是多少?

请注意,是由 Bitek 选择回答哪个问题,并向 Bajtosia 传达他选择的问题以及该问题的答案。

Bitek 太忙于思考如何投资他的钱,所以他只同意回答几个问题。尽管如此,你愿意帮助 Bajtosia 巧妙地提问并确定硬币的数量吗?

交互

这是一个交互式任务。编写一个程序,代表 Bajtosia 向 Bitek 提问并猜出 $x$,使用提供的库。要使用该库,请在你的程序中包含: C++: #include "skalib.h" Python: from skalib import daj_ograniczenie, zapytaj, odpowiedz

你的程序将使用以下命令编译/运行: C++: g++ -O3 -static ska.cpp skalib.cpp -std=c++20 Python: python3 ska.py

要获取 Bajtosia 设定的箱子内硬币数量的上限,可以调用函数: C++: unsigned long long daj_ograniczenie() Python: daj_ograniczenie() -> int

要向 Bitek 提问,请调用函数: C++: std::pair<char, unsigned long long> zapytaj(unsigned long long m) Python: zapytaj(m : int) -> tuple[str, int]

该函数的每次调用都会给出以下两种可能的答案之一: 二元组 $(' / ', w)$,表示 $\lfloor x/m \rfloor = w$($x$ 除以 $m$ 的商等于 $w$), 二元组 $(' \% ', w)$,表示 $x \equiv w \pmod m$($x$ 除以 $m$ 的余数等于 $w$)。

要告诉 Bajtosia 箱子里有多少硬币,请调用函数: C++: void odpowiedz(unsigned long long x) Python: odpowiedz(x : int) -> ()

并传入确定的参数 $x$。调用此函数后,程序应立即终止。

你的程序不得打开任何文件或使用标准输入输出。它可以使用标准诊断输出 (stderr),但请记住,这会消耗宝贵的时间。

样例

测试 0 在 SIO 中对应 $n = 100$ 且 $x = 48$ 的情况。

调用函数 返回值 说明
daj_ograniczenie() $100$ $n = 100$
zapytaj(9) $(' \% ', 3)$ $x \equiv 3 \pmod 9$
zapytaj(10) $(' / ', 4)$ $\lfloor x/10 \rfloor = 4$
odpowiedz(48) $x = 48$ 是唯一符合上述答案的值

子任务

为了获得满分,调用 zapytaj 函数的次数最多为四次。然而,即使超过此限制,也有可能获得部分分数(见下表)。

测试集分为以下子任务。每个子任务的测试由一组或多组独立的测试用例组成。

子任务 数据范围 分数
1 $0 \le x < 2^4$ 5
2 $0 \le x < 2^8$ 6
3 $0 \le x < 2^{16}$ 9
4 $0 \le x < 2^{32}$ 30
5 $0 \le x < 2^{64}$ 50

设 $q$ 为调用 zapytaj 函数的次数。测试得分根据下表计算:

调用次数 得分
$0 \le q \le 4$ 100% 的测试最大得分
$q = 5$ 90%
$q = 6$ 80%
$q = 7$ 60%
$q = 8$ 50%
$q = 9$ 40%
$10 \le q \le 18$ $(37 - 3 \cdot (q - 10))\%$
$19 \le q \le 30$ 10%
$q > 30$ 0%

如果 zapytaj 函数的参数为 0,或者 odpowiedz 函数的参数 $x$ 与预期不符,你的程序将收到“错误答案”判决,该测试得分为 0。

在某些测试中,库可能是自适应的——即不在开始时确定 $x$ 的值,也不在开始时确定对每个可能问题的反应。你可以假设在交互的任何时刻,至少存在一个与迄今为止给出的答案一致的数字 $x$。

说明

在 SIO 的“文件与测试”部分,你可以找到库的示例实现。该实现交替给出 '%' 和 '/' 答案。用于检查解决方案的库可能会对问题选择不同的答案。

注意:在此任务中,SIO 上不提供试运行,也不提供计算机上的评分脚本。

提示:在 C++ 中,标准编译器提供了一个名为 __int128 的 128 位有符号整数类型。请注意,该类型的值不能通过标准方式读取或输出。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1009EditorialOpenStupid Editorial for Problem #11479fast_photon2026-03-16 12:28:04View

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.