Editorial for JDCC '15 Contest 1 P1 - Guessing Game
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Mathematically find the last number. Since you are given the absolute distance from your guess to the answer, it is either above or below (positive or negative) the answer.
Let's imagine the numbers on a number line. is the answer, and are the guesses, and and are the respective distances from the answer.
We can derive the equation . For which in the example above, is positive and is negative. There are four cases of combinations of positive and negative differences (), but we don't need to check them all. We just need to know if .
Let us use some equations. If is positive, then , otherwise, it wouldn't. We can use a system of equations to check if is positive. . We are given differences as absolute values, so the equation is equivalent to . Then we plug in : . If the equation holds true, then is positive (output ), otherwise, is negative (output ).
Time Complexity:
Comments