Guess the NumberAn interactive problem
I'm thinking of a number between 1 and 2×109, inclusive.
Now it will be your job to try to find my number!
To guess a number, just print it out. See the wiki for instructions on flushing output in your language; you must do this after every guess you print.
I will output something back: "Higher" if your number is too low, or "Lower"
if your number is too high.
I will output "OK" if you guessed correctly! Your program should stop at this point.
Your guessing algorithm must be optimal—you must take less than 32 guesses.
You: 10 Me: Lower You: 8 Me: Higher You: 9 Me: OK
Point Value: 5
Time Limit: 1.00s
Memory Limit: 16M
Added: Jan 18, 2009
Too bad now it is not accepting Python 3 code :(
In addition: to flush in Java, use:
(Interestingly enough, neither of the two Java solutions do this, however.)
Right now im doing:
Is this correct?
Remember that it can be any number between 1 and 2 billion (and only between 1 and 2 billion).
For test case #4, the TLE actually means that you've exceeded the allotted amount of guesses (you're taking 32 or more guesses).
For test case #5, your guess is -2147483648. (This is because when you cast it to an int32_t you get 2^32, which when converted to a signed number wraps around.)
The only thing I can tell you is you're approaching the problem incorrectly -- there's a more optimal (read: more correct) way to guess.