CF1386A.Colors

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Linda likes to change her hair color from time to time, and would be pleased if her boyfriend Archie would notice the difference between the previous and the new color. Archie always comments on Linda's hair color if and only if he notices a difference — so Linda always knows whether Archie has spotted the difference or not.

There is a new hair dye series in the market where all available colors are numbered by integers from 11 to NN such that a smaller difference of the numerical values also means less visual difference.

Linda assumes that for these series there should be some critical color difference CC ( 1CN1 \le C \le N ) for which Archie will notice color difference between the current color colornew\mathrm{color}_{\mathrm{new}} and the previous color colorprev\mathrm{color}_{\mathrm{prev}} if colornewcolorprevC\left|\mathrm{color}_{\mathrm{new}} - \mathrm{color}_{\mathrm{prev}}\right| \ge C and will not if colornewcolorprev<C\left|\mathrm{color}_{\mathrm{new}} - \mathrm{color}_{\mathrm{prev}}\right| < C .

Now she has bought NN sets of hair dye from the new series — one for each of the colors from 11 to NN , and is ready to set up an experiment. Linda will change her hair color on a regular basis and will observe Archie's reaction — whether he will notice the color change or not. Since for the proper dye each set should be used completely, each hair color can be obtained no more than once.

Before the experiment, Linda was using a dye from a different series which is not compatible with the new one, so for the clearness of the experiment Archie's reaction to the first used color is meaningless.

Her aim is to find the precise value of CC in a limited number of dyes. Write a program which finds the value of CC by experimenting with the given NN colors and observing Archie's reactions to color changes.

输入格式

输出格式

This is an interactive task. In the beginning you are given a single integer TT ( 1T1001 \leq T \leq 100 ), the number of cases in the test.

For each test case, the input first contains a single integer — the value of NN ( 1<N10181 < N \le 10^{18} ). The value of CC is kept secret by the grading system.

Then your program should make queries writing output in the following format: "? PP ", where PP is an integer ( 1PN1 \le P \le N ) denoting the next color used. For each query the grading system gives an answer in the next line of the input. The answer is 11 if Archie notices the color difference between the last two colors and 00 otherwise. No two queries should have the same PP value.

When your program determines CC , it should output its value in the following format: "= CC ". The grading system will not respond to this output and will proceed with the next test case.

Your program may use at most 64 queries "?" for each test case to find the correct value of CC .

To establish proper communication between your program and the grading system, you should flush the output stream after each query.

$$\begin{array}{ll} \text{Language} & \text{Command} \\ \hline \text{C++} & \texttt{std::cout }\texttt{<}\texttt{<}\texttt{ std::endl;} \\ \text{Java} & \texttt{System.out.flush();} \\ \text{Python} & \texttt{sys.stdout.flush()} \end{array} $$ Flush commands </center><p>Note that <span class="tex-font-style-tt">std::endl</span> writes a newline and flushes the stream.</p><p>It is possible to receive an "Output isn't correct" outcome even after printing a correct answer, if task constraints were violated during the communication. Violating the communication protocol itself may result in an "Execution killed" outcome.</p><p>Submitting user tests requires specifying an input file with the testcase parameters. The format of the input file is "<span class="tex-font-style-tt"> $T$ </span>" in the first line, and then "<span class="tex-font-style-tt"> $N$ $C$ </span>" on a single line for each of the $T$ cases.</p></div><div><div class="section-title">Scoring</div><p>Subtasks: </p><ol> <li> (9 points) $N \\le 64$ </li><li> (13 points) $N \\le 125$ </li><li> (21 points) $N \\le 1000$ </li><li> (24 points) $N \\le 10^9$$$ 2. (33 points) No further constraints.

输入输出样例

  • 输入#1

    1
    
    7
    
    1
    
    1
    
    0
    
    0
    
    1

    输出#1

    ? 2
    
    ? 7
    
    ? 4
    
    ? 1
    
    ? 5
    
    = 4

说明/提示

Comments to the example input line by line:

  1. N=7N = 7 .
  2. Answer to the first query is meaningless (can also be 00 ).
  3. C5C \leq 5 .
  4. 3<C53 < C \leq 5 . It would be wise to check difference 44 . However, this can not be done in the next query since 4+4=84 + 4 = 8 and 44=04 - 4 = 0 both are outside the allowed interval 1P71 \le P \le 7 .
  5. 3<C53 < C \leq 5 .
  6. 3<C43 < C \leq 4 . Therefore, C=4C = 4 .
首页