[Solution] Tournament Countdown Codeforces Solution
This is an interactive problem.
There was a tournament consisting of contestants. The -st contestant competed with the -nd, the -rd competed with the -th, and so on. After that, the winner of the first match competed with the winner of second match, etc. The tournament ended when there was only one contestant left, who was declared the winner of the tournament. Such a tournament scheme is known as the single-elimination tournament.
You don't know the results, but you want to find the winner of the tournament. In one query, you select two integers and , which are the indices of two contestants. The jury will return if won more matches than , if won more matches than , or if their number of wins was equal.
occupied
Find the winner in no more than queries. Here denotes the value of rounded up to the nearest integer.
Note that the tournament is long over, meaning that the results are fixed and do not depend on your queries.
The first line contains a single integer () — the number of test cases.
The only line of input contains a single integer ().
It is guaranteed that the sum of over all test cases does not exceed .
The interaction for each test case begins by reading the integer .
To make a query, output "? a b" () without quotes. Afterwards, you should read one single integer — the answer for your query. You can make at most such queries in each test case.
If you receive the integer instead of an answer or a valid value of , it means your program has made an invalid query, has exceed the limit of queries, or has given incorrect answer on the previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
When you are ready to give the final answer, output "! x" () without quotes — the winner of the tournament. Giving this answer does not count towards the limit of queries. After solving a test case, your program should move to the next one immediately. After solving all test cases, your program should be terminated immediately.
After printing a query or the answer do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hacks
To hack, use the following format.
The first line contains an integer () — the number of test cases.
The first line of each test case contains a single integer ().
The second line of each test case contains numbers on a line — the number of wins of each participant. There should be a sequence of matches that is consistent with the number of wins.
The sum of should not exceed .
No comments:
Post a Comment