Having just landed in the desert Kira remembers that his Strike Gundam is not yet programmed for sand environments. He needs to determine the right amount of pressure that the Strike needs to exert on the sand so that it will neither sink nor float. In other words, he needs the pressure to be an exact number. He knows that the maximum pressure that needs to be exerted is and the minimum pressure is . He wants to find this number in at most guesses.
Interaction
This is an interactive problem. Your program will keep outputting numbers between and inclusive and reading a line of input after each output. The line your program reads will be FLOATS
if your guess for the pressure is too high, SINKS
if your guess for the pressure is too low, and OK
if you have the right number. At this point, your program should terminate.
Each time you output a number, you need to output a new line and flush your output buffers. For example, in Python you can do this with import sys; sys.stdout.flush()
, and in Java with System.out.flush()
.
Sample Interaction
>>>
denotes your output; don't actually print this out.
>>> 1
SINKS
>>> 6
SINKS
>>> 10
SINKS
>>> 40
FLOATS
>>> 32
OK
Comments
Certainly a very creative and unique question!
What is wrong with int
Why can't I use int? I switched to long long and then it passed
Because you mostly might be doing
(left+right) / 2
, whenleft
andright
, it would overflow a 32-bit data type. This is why you need to use a 64-bit data type. The likely reason for your TLE verdict is mostly because you overflowed, and thus the variables went to negative (this is what happens when data types overflow), so your while loop went on forever.Shinn > Kira