#12. International Chairs-Problem Contest
International Chairs-Problem Contest
Problem Statement
This is an interactive problem.
At a regional site, each chair will break if it is subjected to a weight exceeding a non-negative integer . However, you don’t know the value of ; you only know a positive integer such that .
You have two identical chairs available for testing. You can place any weight on each chair to determine whether it will break.
You may ask at most queries. In each query, you choose a weight and learn whether that weight causes a chair to break. Note that if a chair breaks, you cannot use it for further queries, and if both chairs break, you cannot make any more queries.
Your task is to find the exact value of . Specifically, you need to output an integer such that and does not break the chair, but does.
represents the ceiling function of , which rounds up to the nearest integer.
Input Format
Interaction
Initially, you will read an integer (), representing the upper bound for . Then you begin querying to find .
In the guessing process, you may ask at most queries. Each query should be formatted as:
? x, where is an integer such that .
For each query, one of the following responses will be returned:
- If , it returns
0, indicating the chair did not break. - If , it returns
1, indicating the chair broke.
When you are certain of the value of , you should output your answer as follows:
! x, where is your guess for ().
Then your program should terminate.
Note:
- If you exceed the maximum number of queries or submit an incorrect answer, you will receive
-1and the solution will be judged as Wrong Answer. In this case, your program should terminate immediately to avoid unnecessary consequences. - You have only two chairs, so after accumulating two responses of
1, all subsequent queries will return-1, which is also considered Wrong Answer.
After each query or answer output, remember to print a newline and flush the output buffer to avoid Time Limit Exceeded errors. You can flush the output buffer as follows:
- In C++, use
fflush(stdout)orcout.flush(). - In Java, use
System.out.flush(). - In Pascal, use
flush(output). - In Python, use
sys.stdout.flush(). - For other languages, refer to the respective documentation.
Output Format
Example
Example Input
10
1
0
0
0
1
Example Output
? 5
? 1
? 2
? 3
? 4
! 3
Constraints
For of the test cases, the interactor is non-adaptive, meaning that is pre-determined.
For the remaining of the test cases, the interactor is adaptive, meaning that the interactor does not initially have a fixed answer for but will determine a value during the interaction that meets the problem’s requirements.
相关
在下列比赛中: