题库练习 Too Many Impostors (easy version)
← 上一题 下一题 →

A14676 | Too Many Impostors (easy version)

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

This is an interactive problem. The only difference between the easy and hard version is the limit on number of questions.

There are $n$ players labelled from $1$ to $n$ . It is guaranteed that $n$ is a multiple of $3$ .

Among them, there are $k$ impostors and $n-k$ crewmates. The number of impostors, $k$ , is not given to you. It is guaranteed that $\frac{n}{3} < k < \frac{2n}{3}$ .

In each question, you can choose three distinct integers $a$ , $b$ , $c$ ( $1 \le a, b, c \le n$ ) and ask: "Among the players labelled $a$ , $b$ and $c$ , are there more impostors or more crewmates?" You will be given the integer $0$ if there are more impostors than crewmates, and $1$ otherwise.

Find the number of impostors $k$ and the indices of players that are impostors after asking at most $2n$ questions.

The jury is adaptive, which means the indices of impostors may not be fixed beforehand and can depend on your questions. It is guaranteed that there is at least one set of impostors which fulfills the constraints and the answers to your questions at any time.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 100$ ). Description of the test cases follows.

The first and only line of each test case contains a single integer $n$ ( $6 \le n < 10^4$ , $n$ is a multiple of $3$ ) — the number of players.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^4$ .

输出格式

For each test case, the interaction starts with reading $n$ .

Then you are allowed to make at most $2n$ questions in the following way:

"? a b c" ( $1 \le a, b, c \le n$ , $a$ , $b$ and $c$ are pairwise distinct).

After each one, you should read an integer $r$ , which is equal to $0$ if there are more impostors than crewmates among players labelled $a$ , $b$ and $c$ , and equal to $1$ otherwise.

Answer $-1$ instead of $0$ or $1$ means that you made an invalid query or exceeded the number of queries. Exit immediately after receiving $-1$ and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

When you have found the indices of all impostors, print a single line "! " (without quotes), followed by the number of impostors $k$ , followed by $k$ integers representing the indices of the impostors. Please note that you must print all this information on the same line.

After printing the answer, your program must then continue to solve the remaining test cases, or exit if all test cases have been solved.

After printing the queries and answers do not forget to output end of line and flush the output buffer. Otherwise, you will get the Idleness limit exceeded verdict. To do flush use:

- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- Read documentation for other languages.

Hacks

You cannot make hacks in this problem.

输入输出样例

输入 #1
2
6

0

1

9

1
输出 #1
? 1 2 3

? 3 4 5

! 3 4 1 2

? 7 1 9

! 4 2 3 6 8
C++ 编辑器
输入
输出