CF1780D Bit Guessing Game
题目描述
这是一道交互题。
Kira 和 Hayato 正在玩一种猜数游戏,Kira 想,Hayato 猜。
对于每一轮游戏,设 Kira 想的数为 $n$。初始时,Kira 会给出 $cnt$,表示 $n$ 的二进制中 $1$ 的个数。Hayato 只能进行以下两种操作:
1. `- x`:修改操作。Kira 会将 $n$ 减去 $x$(注意此处 $n$ 会被修改),并给出此时的 $cnt$。特别地,若 $x > n$,则 Kira 直接获胜。
2. `! x`:查询操作。Kira 会将 $x$ 与最初的 $n$ 对比,若二者相同则 Hayato 获胜,反之 Kira 获胜,这轮游戏立即结束。
他们一共会进行 $t$ 轮游戏,你需要帮助 Hayato 在每一轮中获胜。同时,Kira 并不是一个很有耐心的人,因此你进行操作 1 的次数不能超过 $30$。
注意样例中的空行只是为了显示更清晰,不会出现在实际评测中。
输入格式
第一行包含一个整数 $t(1 \le t \le 500)$,表示有 $t$ 组测试用例。
对于每组测试用例,首行均为一个整数 $cnt$,表示 $n$ 的二进制中 $1$ 的个数。
保证 $1 \le n \le 10^9$。
输出格式
对于每个操作 1,输出单独的一行 `- x`;相应地,对于每个操作 2,输出单独的一行 `! n`。
每个操作 1 完成后,交互库会输出一行一个整数 $cnt$,表示修改后的 $n$ 的二进制中 $1$ 的个数。
再次强调,每一轮 Hayato 进行操作 1 的次数不能超过 $30$。
确定初始时 $n$ 的值后,可进行操作 2 验证答案。
注意:每次输出任意操作后需要刷新输出。这里给出部分语言刷新输出的代码:
| 语言 | 代码 |
| :----: | :--------------------------------: |
| C++ | `fflush(stdout)` 或 `cout.flush()` |
| Java | `System.out.flush()` |
| Pascal | `flush(output)` |
| Python | `stdout.flush()` |
说明/提示
For example, the number of unit bits in number $ 6 $ is $ 2 $ , because binary notation of $ 6 $ is $ 110 $ . For $ 13 $ the number of unit bits is $ 3 $ , because $ 13_{10} = 1101_2 $ .
In the first test case, $ n = 1 $ , so the input is the number $ 1 $ . After subtracting one from $ n $ , it becomes zero, so the number of unit bits in it is $ 0 $ .
In the third test case, $ n = 3 $ , which in binary representation looks like $ 3_{10} = 11_2 $ , so the input is the number of ones, that is $ 2 $ . After subtracting $ 2 $ , $ n = 1 $ , so the number of unit bits is now $ 1 $ . After subtracting one from $ n $ , it becomes equal to zero.
Note that the blank lines in the input and output examples are shown for clarity and are not present in the actual interaction.