EIUGUESSNUM - Number Guessing Game
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
5.0s
Giới hạn bộ nhớ:
1G
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
You play a guessing game: The judge has chosen a secret number in a given range ~[a, b]~. Your task is to guess this number through a series of queries. After each guess, the judge will tell you whether your guess is too low, too high, or correct.
Your goal is to find the secret number using as few guesses as possible.
Input/Output (Interactive)
- This is an interactive problem. Your program must interact with the judge by reading input and writing output in turns.
Initial Input
- The first line contains two integers ~a~ and ~b~ ~(0 ≤ a ≤ b ≤ 10^{18})~, representing the range ~[a, b]~ in which the secret number lies.
Interaction Protocol
- After reading a and b, your program should repeatedly:
- Output a guess: Print a single integer - your guessed number
- Flush the output: Use
System.out.flush()in Java - Read the response: Read a string from input, which will be one of:
LOW- Your guess is too low (the secret number is larger)HIGH- Your guess is too high (the secret number is smaller)WIN- Your guess is correct! The game ends.
Important:
- You must flush the output buffer after each guess, otherwise the judge won't receive your output and the program will hang.
Scoring:
- Each test case is scored based on the number of guesses you make. The total score is the sum of scores across all test cases.
Example Interaction
Judge: 4 30
You: 17
Judge: HIGH
You: 10
Judge: HIGH
You: 7
Judge: LOW
You: 8
Judge: WIN
Constraints
- ~0 ≤ a ≤ b ≤ 10^{18}~
- The secret number is always within [a, b]
- You can make at most ~100~ guesses per test case
Bình luận