CF2273E.Six-Seven Bags

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Ale and Sofia want to win every aura battle in the city, so they are preparing a street-magic trick with bags of coins.

There are nn bags on a table. The ii-th bag contains aia_i coins. In every bag, all coins are of the same type: either 66-coins, which weigh 66 grams each, or 77-coins, which weigh 77 grams each. Exactly one bag contains 66-coins, and the other n−1n - 1 bags contain 77-coins. Ale and Sofia know the array aa, but not which bag contains the 66-coins.

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.

Let f(a)f(a) be the minimum number of queries needed to guarantee finding the 66-coin bag, regardless of which bag it is. Help Ale and Sofia find this bag using at most f(a)f(a) queries.

The interactor is adaptive. The index of the 66-coin bag may change during the interaction, as long as all previous answers remain consistent.

这是一个交互式问题。

Ale 和 Sofia 想要赢得城市中的每一场“灵光之战”,因此他们正在准备一个街头魔术戏法,使用装有硬币的袋子。

桌上共有 nn 个袋子。第 ii 个袋子中有 aia_i 枚硬币。每个袋子中的所有硬币均为同一种类型:要么是重 66 克的“6-硬币”,要么是重 77 克的“7-硬币”。恰好有一个袋子中装的是 6-硬币,其余 n−1n - 1 个袋子中装的都是 7-硬币。Ale 和 Sofia 知道数组 aa,但不知道哪个袋子装的是 6-硬币。

在一次查询中,他们可以从每个袋子中任选若干枚硬币(也可以不选),并获知所选硬币的总重量。每次查询结束后,所有被选出的硬币都会被放回原袋。

令 f(a)f(a) 表示无论 6-硬币袋是哪一个,都能保证找出它的最小查询次数。请帮助 Ale 和 Sofia 在至多 f(a)f(a) 次查询内找出该袋子。

该交互器是自适应的:6-硬币袋的编号可能在交互过程中发生变化,但必须保证所有此前给出的回答仍保持一致。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1052 \le n \le 10^5) — the number of bags.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) — the number of coins in each bag.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)—— 表示袋子的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 表示每个袋子中的硬币数量。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

null

输入输出样例

  • 输入#1

    2
    5
    1 1 2 2 2
    
    34
    
    33
    
    4
    3 2 4 3
    
    47

    输出#1

    ? 1 0 1 2 1
    
    ? 1 1 2 0 1
    
    ! 3
    
    
    ? 3 2 2 0
    
    ! 2

说明/提示

The example interaction does not represent an optimal strategy and is only shown to demonstrate the input/output format.

The extra blank lines in the example are for readability only and are not part of the actual input or output.

In the first test case, n=5n = 5 and a=[1,1,2,2,2]a = [1, 1, 2, 2, 2]. The third bag contains 66-coins. The displayed weights are calculated as follows:

  • ? 1 0 1 2 1: five coins are selected and b3=1b_3 = 1, giving 7⋅(1+0+2+1)+6⋅1=347 \cdot (1 + 0 + 2 + 1) + 6 \cdot 1 = 34.
  • ? 1 1 2 0 1: five coins are selected and b3=2b_3 = 2, giving 7⋅(1+1+0+1)+6⋅2=337 \cdot (1 + 1 + 0 + 1) + 6 \cdot 2 = 33.

The participant then outputs ! 3 to identify the third bag.

In the second test case, n=4n = 4 and a=[3,2,4,3]a = [3, 2, 4, 3]. The second bag contains 66-coins. The query ? 3 2 2 0 selects seven coins, including two from the second bag, so the response is 7⋅(3+2+0)+6⋅2=477 \cdot (3 + 2 + 0) + 6 \cdot 2 = 47.

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.

示例交互并不代表最优策略,仅用于演示输入/输出格式。

示例中的额外空行仅为提高可读性,不属于实际输入或输出。

在第一个测试用例中,n=5n = 5,a=[1,1,2,2,2]a = [1, 1, 2, 2, 2]。第三个袋子装有面值为 66 的硬币。所显示的重量按如下方式计算:

  • ? 1 0 1 2 1:共选取五枚硬币,且 b3=1b_3 = 1,因此结果为 7⋅(1+0+2+1)+6⋅1=347 \cdot (1 + 0 + 2 + 1) + 6 \cdot 1 = 34。
  • ? 1 1 2 0 1:共选取五枚硬币,且 b3=2b_3 = 2,因此结果为 7⋅(1+1+0+1)+6⋅2=337 \cdot (1 + 1 + 0 + 1) + 6 \cdot 2 = 33。

随后,参与者输出 ! 3,以确定第三个袋子。

在第二个测试用例中,n=4n = 4,a=[3,2,4,3]a = [3, 2, 4, 3]。第二个袋子装有面值为 66 的硬币。查询 ? 3 2 2 0 共选取七枚硬币,其中包含来自第二个袋子的两枚硬币,因此响应为 7⋅(3+2+0)+6⋅2=477 \cdot (3 + 2 + 0) + 6 \cdot 2 = 47。

随后,参与者输出 ! 2。该答案对于图示中隐藏袋子的选择是正确的,但该查询无法区分第二个袋子与第三个袋子。

输入解题思路,AI测评打分。不知道怎么写?

首页