六克与七克硬币袋AI (CI翻译)
This is an interactive problem.
这是一道交互题。AI (CI翻译)
Ale and Sofia want to win every aura battle in the city, so they are preparing a street-magic trick with bags of coins.
Ale 和 Sofia 想赢下城里的每一场光环对战,因此他们正准备一个用硬币袋表演的街头魔术。AI (CI翻译)
There are $n$ bags on a table. The $i$-th bag contains $a_i$ coins. In every bag, all coins are of the same type: either $6$-coins, which weigh $6$ grams each, or $7$-coins, which weigh $7$ grams each. Exactly one bag contains $6$-coins, and the other $n - 1$ bags contain $7$-coins. Ale and Sofia know the array $a$, but not which bag contains the $6$-coins.
桌上有 $n$ 个袋子。第 $i$ 个袋子里有 $a_i$ 枚硬币。每个袋子里的硬币类型都相同:要么是每枚重 $6$ 克的硬币,要么是每枚重 $7$ 克的硬币。恰好有一个袋子装着每枚重 $6$ 克的硬币,其余 $n - 1$ 个袋子装的都是每枚重 $7$ 克的硬币。Ale 和 Sofia 知道数组 $a$,但不知道哪个袋子装着每枚重 $6$ 克的硬币。AI (CI翻译)
In one query, they may select any number of coins from each bag (possibly zero) and learn their total weight. All selected coins are returned to their bags after each query.
每次查询中,他们可以从每个袋子里取出任意数量的硬币(也可以不取),并获知所取硬币的总重量。每次查询结束后,所有取出的硬币都会放回原袋。AI (CI翻译)
Let $f(a)$ be the minimum number of queries needed to guarantee finding the $6$-coin bag, regardless of which bag it is. Help Ale and Sofia find this bag using at most $f(a)$ queries.
令 $f(a)$ 表示无论哪个袋子装着每枚重 $6$ 克的硬币,都能保证找出该袋子所需的最少查询次数。请帮助 Ale 和 Sofia 使用不超过 $f(a)$ 次查询找出这个袋子。AI (CI翻译)
The interactor is adaptive. The index of the $6$-coin bag may change during the interaction, as long as all previous answers remain consistent.
交互器是自适应的。在交互过程中,装有每枚重 $6$ 克硬币的袋子编号可能发生变化,但必须保证之前的所有回答始终一致。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个输入包含多组测试用例。第一行包含测试用例数 $t$($1 \le t \le 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case contains a single integer $n$ ($2 \le n \le 10^5$) — the number of bags.
每个测试用例的第一行包含一个整数 $n$($2 \le n \le 10^5$)——袋子的数量。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the number of coins in each bag.
每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le n$)——每个袋子中的硬币数量。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.
保证所有测试用例的 $n$ 之和不超过 $10^5$。AI (CI翻译)
Interaction
交互
AI (CI翻译)For each test case, first read $n$ and the array $a$. Then you may make queries.
对于每个测试用例,首先读取 $n$ 和数组 $a$。之后可以进行查询。AI (CI翻译)
To make a query, output a line in the following format:
进行一次查询时,按照以下格式输出一行:AI (CI翻译)
?$b_1\; b_2\; \ldots\; b_n$($0 \le b_i \le a_i$) — where$b_i$is the number of coins selected from the$i$-th bag.
?$b_1\; b_2\; \ldots\; b_n$($0 \le b_i \le a_i$)——其中$b_i$表示从第$i$个袋子中取出的硬币数量。
After each query, read a single integer — the total weight of the selected coins, $\sum_{i=1}^{n} b_i \cdot w_i$, where $w_i = 6$ if the $i$-th bag contains $6$-coins and $w_i = 7$ otherwise. This weight may exceed the range of a $32$-bit integer.
每次查询后,读取一个整数——所取硬币的总重量,即 $\sum_{i=1}^{n} b_i \cdot w_i$,其中如果第 $i$ 个袋子装着每枚重 $6$ 克的硬币,则 $w_i = 6$;否则 $w_i = 7$。这个重量可能超出 32 位整数的范围。AI (CI翻译)
When you have determined the $6$-coin bag, output a line in the following format:
确定装有每枚重 $6$ 克硬币的袋子后,按照以下格式输出一行:AI (CI翻译)
!$i$($1 \le i \le n$) — where$i$is the index of the bag with$6$-coins.
!$i$($1 \le i \le n$)——其中$i$是装有每枚重$6$克硬币的袋子的编号。
This line does not count toward the limit of $f(a)$ queries. After a correct answer, proceed to the next test case, or terminate your program if it was the last test case. The interactor does not send a confirmation value after a correct answer.
这行输出不计入 $f(a)$ 次查询的限制。回答正确后,继续处理下一个测试用例;如果这是最后一个测试用例,则终止程序。交互器在正确回答后不会发送确认信息。AI (CI翻译)
If you exceed the query limit or report an incorrect bag, the interactor will output -1, and you will receive a Wrong Answer verdict. Upon receiving -1 instead of any expected input, your program must terminate immediately. Otherwise, you may receive an arbitrary verdict because your program might try to read from a closed stream. Invalid output may also cause the interactor to terminate immediately.
如果超过查询次数限制或报告了错误的袋子,交互器会输出 -1,你将收到 Wrong Answer 评测结果。若读取预期输入时得到 -1,程序必须立即终止。否则,由于程序可能尝试从已关闭的流中读取数据,你可能会收到任意评测结果。无效输出也可能导致交互器立即终止。AI (CI翻译)
After printing a query or the answer, output a newline and flush the output. Otherwise, you may receive an Idleness Limit Exceeded verdict. To flush the output, use:
输出查询或答案后,请换行并刷新输出缓冲区。否则,你可能会收到 Idleness Limit Exceeded 评测结果。刷新输出缓冲区的方法如下:AI (CI翻译)
fflush(stdout)orcout.flush()in C++;System.out.flush()in Java;sys.stdout.flush()in Python;std::io::stdout().flush()in Rust;- see the documentation for other languages.
- 在 C++ 中使用
fflush(stdout)或cout.flush(); - 在 Java 中使用
System.out.flush(); - 在 Python 中使用
sys.stdout.flush(); - 在 Rust 中使用
std::io::stdout().flush(); - 其他语言请参阅相关文档。
Hacks
黑客测试AI (CI翻译)
To hack, use the following format.
黑客测试的输入格式如下。AI (CI翻译)
The first line should contain the number of test cases $(1 \le t \le 5000)$. The description of the test cases follows.
第一行包含测试用例数 $(1 \le t \le 5000)$。接下来是各测试用例的描述。AI (CI翻译)
The first line of each test case should contain an integer $n$ ($2 \le n \le 10^5$) — the number of bags — followed by the string manual, followed by an integer $k$ ($1 \le k \le n$) — the index of the $6$-coin bag.
每个测试用例的第一行包含一个整数 $n$($2 \le n \le 10^5$)——袋子的数量;随后是字符串 manual,再随后是一个整数 $k$($1 \le k \le n$)——装有每枚重 $6$ 克硬币的袋子的编号。AI (CI翻译)
The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the number of coins in each bag.
每个测试用例的第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($1 \le a_i \le n$)——每个袋子中的硬币数量。AI (CI翻译)
The sum of $n$ over all test cases should not exceed $10^5$.
所有测试用例的 $n$ 之和不应超过 $10^5$。AI (CI翻译)
Note
说明
AI (CI翻译)The example interaction does not represent an optimal strategy and is only shown to demonstrate the input/output format.
样例交互并不代表最优策略,仅用于展示输入输出格式。AI (CI翻译)
The extra blank lines in the example are for readability only and are not part of the actual input or output.
样例中的额外空行仅为方便阅读,不属于实际输入或输出。AI (CI翻译)
In the first test case, $n = 5$ and $a = [1, 1, 2, 2, 2]$. The third bag contains $6$-coins. The displayed weights are calculated as follows:
在第一个测试用例中,$n = 5$ 且 $a = [1, 1, 2, 2, 2]$。第三个袋子装着每枚重 $6$ 克的硬币。展示的重量计算如下:AI (CI翻译)
? 1 0 1 2 1: five coins are selected and$b_3 = 1$, giving$7 \cdot (1 + 0 + 2 + 1) + 6 \cdot 1 = 34$.? 1 1 2 0 1: five coins are selected and$b_3 = 2$, giving$7 \cdot (1 + 1 + 0 + 1) + 6 \cdot 2 = 33$.
? 1 0 1 2 1:取出了五枚硬币,且$b_3 = 1$,因此重量为$7 \cdot (1 + 0 + 2 + 1) + 6 \cdot 1 = 34$。? 1 1 2 0 1:取出了五枚硬币,且$b_3 = 2$,因此重量为$7 \cdot (1 + 1 + 0 + 1) + 6 \cdot 2 = 33$。
The participant then outputs
随后,参赛者输出AI (CI翻译)
! 3
! 3AI (CI翻译)
to identify the third bag.
以指出第三个袋子。AI (CI翻译)
In the second test case, $n = 4$ and $a = [3, 2, 4, 3]$. The second bag contains $6$-coins. The query ? 3 2 2 0 selects seven coins, including two from the second bag, so the response is $7 \cdot (3 + 2 + 0) + 6 \cdot 2 = 47$.
在第二个测试用例中,$n = 4$ 且 $a = [3, 2, 4, 3]$。第二个袋子装着每枚重 $6$ 克的硬币。查询 ? 3 2 2 0 取出了七枚硬币,其中包括第二个袋子里的两枚,因此回答为 $7 \cdot (3 + 2 + 0) + 6 \cdot 2 = 47$。AI (CI翻译)
The participant then outputs ! 2. This answer is correct for the illustrated choice of the hidden bag, but the query does not distinguish the second bag from the third bag.
随后,参赛者输出 ! 2。对于示例中隐藏袋子的选择,这个答案是正确的,但该查询无法区分第二个袋子和第三个袋子。AI (CI翻译)
样例
2
5
1 1 2 2 2
34
33
4
3 2 4 3
47
? 1 0 1 2 1
? 1 1 2 0 1
! 3
? 3 2 2 0
! 2
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。