CF1008E.Guess two numbers
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is an interactive problem.
Vasya and Vitya play a game. Vasya thought of two integers a and b from 1 to n and Vitya tries to guess them. Each round he tells Vasya two numbers x and y from 1 to n . If both x=a and y=b then Vitya wins. Else Vasya must say one of the three phrases:
- x is less than a ;
- y is less than b ;
- x is greater than a or y is greater than b .
Vasya can't lie, but if multiple phrases are true, he may choose any of them. For example, if Vasya thought of numbers 2 and 4 , then he answers with the phrase 3 to a query (3,4) , and he can answer with the phrase 1 or phrase 3 to a query (1,5) .
Help Vitya win in no more than 600 rounds.
输入格式
The first line contains a single integer n ( 1≤n≤1018 ) — the upper limit of the numbers.
输出格式
First, you need to read the number n , after that you can make queries.
To make a query, print two integers: x and y ( 1≤x,y≤n ), then flush the output.
After each query, read a single integer ans ( 0≤ans≤3 ).
If ans>0 , then it is the number of the phrase said by Vasya.
If ans=0 , it means that you win and your program should terminate.
If you make more than 600 queries or make an incorrect query, you will get Wrong Answer.
Your solution will get Idleness Limit Exceeded, if you don't print anything or forget to flush the output.
To flush you need to do the following right after printing a query and a line end:
- fflush(stdout) in C++;
- System.out.flush() in Java;
- stdout.flush() in Python;
- flush(output) in Pascal;
- For other languages see documentation.
Hacks format
For hacks, use the following format:
In the first line, print a single integer n ( 1≤n≤1018 ) — the upper limit of the numbers.
In the second line, print two integers a and b ( 1≤a,b≤n ) — the numbers which Vasya thought of.
In the third line, print a single integer m ( 1≤m≤105 ) — the number of instructions for the interactor.
In each of the next m lines, print five integers: xi , yi , ri12 , ri13 , and ri23 ( 1≤xi,yi≤n ), where riST equals to either number S or number T .
While answering the query xy , the interactor finds a number i from 1 to n with the minimal value ∣x−xi∣+∣y−yi∣ . If multiple numbers can be chosen, the least i is preferred. Then the interactor answers to the query, but if there are two phrases S and T that can be given, then riST is chosen.
For example, the sample test data file contains the following:
<br></br>5<br></br>2 4<br></br>2<br></br>2 5 1 1 2<br></br>4 1 2 3 3<br></br>
输入输出样例
输入#1
5 3 3 2 1 0
输出#1
4 3 3 4 3 3 1 5 2 4
说明/提示
Let's analyze the sample test. The chosen numbers are 2 and 4 . The interactor was given two instructions.
For the query (4,3) , it can return 2 or 3 . Out of the two instructions the second one is chosen, so the interactor returns a223=3 .
For the query (3,4) , it can return only 3 .
For the query (3,3) , it can return 2 or 3 . Out of the two instructions the first one is chosen (since in case of equal values, the least number is preferred), so the interactor returns a123=2 .
For the query (1,5) , it can return 1 or 3 . Out of the two instructions the first one is chosen, so the interactor returns a113=1 .
In the fifth query (2,4) , the numbers are guessed correctly, the player wins.