Codeforces Round 1056 (Div. 2)
D
Batteries
Codeforces
1800
原题
← CE →
翻译中…

This is an interactive problem. Refer to the Interaction section below for better understanding.

翻译中…

There are $n$ ($2 \le n \le 40$) batteries numbered $1, 2, \ldots, n$. Some of them work while the others don't. Let $a$ be the number of batteries that work. It is guaranteed that $\mathbf{a \geq 2}$.

翻译中…

You are given $n$ but not $a$.

翻译中…

There is a flashlight which can hold two batteries and it only turns on when both batteries work. The batteries have been shuffled and you don't know which ones work and which ones don't. You can choose two batteries and try them in the flashlight.

翻译中…

You want to find a pair of batteries that work. However, you are worried about breaking the flashlight, so you want to limit the amount of trials you attempt.

翻译中…

Therefore, you should find a pair of working batteries using at most $\left \lfloor \frac{n^2}{a} \right \rfloor$ trials.

翻译中…

The interactor is adaptive. This means that whether battery $i$ ($1 \le i \le n$) works is not fixed and may change during the interaction. However, it is guaranteed that there exists a configuration of $a$ working batteries that is consistent with the information that you have received so far.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 40$) — the number of batteries.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $200$.

翻译中…

Interaction

翻译中…

The interaction for each test case begins with reading the integer $n$.

翻译中…

To make a query, print a single line with two integers in the following format:

翻译中…
  • $\mathbb{u}\,\mathbb{v}$ ($1 \leq u, v \leq n$ and $u \neq v$) — the indices of the batteries you want to test.
翻译中…

After that, read a single integer $x$ — indicating whether the flashlight turned on after inserting those $2$ batteries. If $x=1$, the flashlight turned on. Otherwise, if $x=0$, the flashlight did not turn on.

翻译中…

After finding a pair of batteries that turns the flashlight on, the interaction of the test case is considered successful, and it will terminate. After that, the interaction continues with the next test case.

翻译中…

After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

翻译中…

Hacks

翻译中…

Hacks are disabled for this problem.

翻译中…

$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.

翻译中…

Note

翻译中…

In the first test, there are $3$ batteries. Only batteries $2$ and $3$ work. Therefore, $a=2$ and we have to find a pair of batteries that work in $\lfloor \frac{n^2}{a} \rfloor = \lfloor \frac{3^2}{2} \rfloor = 4$ queries.

翻译中…

The interaction proceeds as follows:

翻译中…

ParticipantJuryExplanation—$3$There are $3$ batteries in this test case$1$ $2$$0$The solution asks whether batteries $1$ and $2$ turn the flashlight on. The jury responds that they don't.$2$ $3$$1$The solution asks whether batteries $2$ and $3$ turn the flashlight on. The jury responds that they do. A pair of batteries that work is found, so the interaction of the first test case terminates successfully.

翻译中…

In the second test case, there are $10$ batteries. Only batteries $1$, $4$, $6$ and $9$ work. Therefore, $a=4$ and we have to find a pair of batteries that work in $\lfloor \frac{n^2}{a} \rfloor = \lfloor \frac{10^2}{4} \rfloor = 25$ queries.

翻译中…

The interaction proceeds as follows:

翻译中…

ParticipantJuryExplanation—$10$There are $10$ batteries in this test case.$1$ $2$$0$The solution asks whether batteries $1$ and $2$ turn the flashlight on. The jury responds that they don't.$1$ $3$$0$The solution asks whether batteries $1$ and $3$ turn the flashlight on. The jury responds that they don't.$1$ $4$$1$The solution asks whether batteries $1$ and $4$ turn the flashlight on. The jury responds that they do. A pair of batteries that work is found, so the interaction of the first test case terminates successfully.

翻译中…

Note that the line breaks in the example input and output are for the sake of clarity, and do not occur in the real interaction.

翻译中…

样例

Input #1
2
3

0

1
10

0

0

1
Output #1
1 2

2 3

1 2

1 3

1 4
InputCopy OutputCopy
题目信息
题号
2155D
时间限制
2 s
内存限制
256 MB
标签
暴力
构造
图匹配
图论
交互题
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。