codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1999G1.md (4834B)


      1 Source: https://codeforces.com/problemset/problem/1999/G1
      2 
      3 G1. Ruler (easy version)
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 This is the easy version of the problem. The only difference between the two versions is that in this version, you can make at most $\mathbf{10}$ queries.
     22 
     23 This is an interactive problem. If you are unsure how interactive problems work, then it is recommended to read [the guide for participants](https://codeforces.com/blog/entry/45307).
     24 
     25 We have a secret ruler that is missing one number $x$ ($2 \leq x \leq 999$). When you measure an object of length $y$, the ruler reports the following values:
     26 
     27 * If $y \lt x$, the ruler (correctly) measures the object as having length $y$.
     28 * If $y \geq x$, the ruler incorrectly measures the object as having length $y+1$.
     29 
     30  ![](https://espresso.codeforces.com/a98908c8e65eba44622cf7a3ee2ee84099990643.png)
     31 
     32 The ruler above is missing the number $4$, so it correctly measures the first segment as length $3$ but incorrectly measures the second segment as length $6$ even though it is actually $5$.
     33 
     34 You need to find the value of $x$. To do that, you can make queries of the following form:
     35 
     36 * $\texttt{?}~a~b$ — in response, we will measure the side lengths of an $a \times b$ rectangle with our ruler and multiply the results, reporting the measured area of the rectangle back to you. For example, if $x=4$ and you query a $3 \times 5$ rectangle, we will measure its side lengths as $3 \times 6$ and report $18$ back to you.
     37 
     38 Find the value of $x$. You can ask at most $\mathbf{10}$ queries.
     39 
     40 Input
     41 
     42 Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
     43 
     44 Interaction
     45 
     46 There is no initial input for each test case. You should begin the interaction by asking a query.
     47 
     48 To make a query, output a single line of the form $\texttt{?}~a~b$ ($1 \leq a, b \leq 1000$). In response, you will be told the measured area of the rectangle, according to our secret ruler.
     49 
     50 When you are ready to print the answer, output a single line of the form $\texttt{!}~x$ ($2 \leq x \leq 999$). After that, proceed to process the next test case or terminate the program if it was the last test case. Printing the answer does not count as a query.
     51 
     52 The interactor is not adaptive, meaning that the answer is known before the participant asks the queries and doesn't depend on the queries asked by the participant.
     53 
     54 If your program makes more than $10$ queries for one set of input data, makes an invalid query, or prints the wrong value of $x$, then the response to the query will be $-1$. After receiving such a response, your program should immediately terminate to receive the verdict Wrong Answer. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.
     55 
     56 After printing a query do not forget to output the end of line and flush the output. Otherwise, you may get Idleness limit exceeded verdict. To do this, use:
     57 
     58 * fflush(stdout) or cout.flush() in C++;
     59 * System.out.flush() in Java;
     60 * flush(output) in Pascal;
     61 * stdout.flush() in Python;
     62 * see the documentation for other languages.
     63 
     64 Hacks
     65 
     66 To make a hack, use the following format.
     67 
     68 The first line should contain a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases.
     69 
     70 The only line of each test case should contain a single integer $x$ ($2 \leq x \leq 999$) — the missing number on the ruler.
     71 
     72 Example
     73 
     74 Input
     75 
     76 ```
     77 2
     78 
     79 18
     80 
     81 25
     82 
     83 9999
     84 ```
     85 
     86 Output
     87 
     88 ```
     89 ? 3 5
     90 
     91 ? 4 4
     92 
     93 ! 4
     94 ? 99 100
     95 
     96 ! 100
     97 ```
     98 
     99 Note
    100 
    101 In the first test, the interaction proceeds as follows.
    102 
    103 |  |  |  |
    104 | --- | --- | --- |
    105 | Solution | Jury | Explanation |
    106 |  | $\texttt{2}$ | There are 2 test cases. |
    107 | $\texttt{? 3 5}$ | $\texttt{18}$ | Secretly, the jury picked $x=4$. The solution requests the $3 \times 5$ rectangle, and the jury responds with $3 \times 6 = 18$, as described in the statement. |
    108 | $\texttt{? 4 4}$ | $\texttt{25}$ | The solution requests the $4 \times 4$ rectangle, which the jury measures as $5 \times 5$ and responds with $25$. |
    109 | $\texttt{! 4}$ |  | The solution has somehow determined that $x=4$, and outputs it. Since the output is correct, the jury continues to the next test case. |
    110 | $\texttt{? 99 100}$ | $\texttt{1}$ | Secretly, the jury picked $x=100$. The solution requests the $99 \times 100$ rectangle, which the jury measures as $99 \times 101$ and responds with $9999$. |
    111 | $\texttt{! 100}$ |  | The solution has somehow determined that $x=100$, and outputs it. Since the output is correct and there are no more test cases, the jury and the solution exit. |
    112 
    113 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.