Guessing Game
Time limit1sMemory limit128 MB
Find the fewest adaptive rounds of up to K cell reveals that always identify the length of a painted prefix of N cells.
- Level
Medium7 of 10
- Topics
- Binary search, Combinatorics, Math
- Solved
- No attempts yet
Problem
Hektor loves looking after his younger sister Kornelia, and the two never run out of games to play. Today they are playing a guessing game.
The game needs square cells laid out in a row. First, Kornelia paints a run of cells starting from the front: she paints the first cells, where can be any value from to (she may paint none of them, or all of them). When she is done, she covers each cell with a piece of paper so you cannot tell whether it was painted.
Now it is Hektor's turn. He must figure out how many cells Kornelia painted. Hektor may uncover cells of his choice over several rounds; in each round he may uncover (simultaneously) at most of the still-covered cells. Each uncovered cell reveals whether or not it was painted.
Compute the minimum number of rounds for which a strategy of choosing which cells to uncover exists that guarantees determining the number of painted cells.
Input
The first line contains the number of test cases (). Each of the next lines contains the two natural numbers and described above, separated by a space ().
Output
For each test case, print on its own line the minimum number of rounds that guarantees success.
Hint
For , , two rounds are enough, for example with the following strategy. In the first round Hektor uncovers cells 2 and 4.
- If both cells 2 and 4 turn out painted, uncovering cell 5 in the second round tells whether Kornelia painted 4 or 5 cells.
- If cell 2 is painted but cell 4 is not, uncovering cell 3 in the second round tells whether she painted 2 or 3 cells.
- If neither cell 2 nor cell 4 is painted, uncovering cell 1 in the second round tells whether she painted 1 cell or none.
One round, on the other hand, is not enough: whatever cells Hektor uncovers in the first round, it can still happen that he cannot pin down the count. For example, if he uncovers cells 2 and 4 and only cell 2 is painted, he cannot tell 2 from 3; and if he uncovers cells 1 and 2 and both are painted, he cannot tell which of 2, 3, 4, or 5 cells were painted.