GLASS BALLS
The company "Youla" manufactures glass balls from special glass. Every day it produces a set of balls of the same strength. However, different sets may have different strengths. To measure the strength of each set, the production engineer follows the following procedure: He drops some balls (from a set) from different levels of a building and thus represents their strength with the lowest level at which the ball will break in free fall. Each level is determined by a floor. At first, he decides to go up one floor at a time and perform the experiment successively. Therefore, if a ball has a strength of 10, he will perform 10 attempts. Then he decided to do something faster, at the cost of using more balls. So he decided to perform random experiments from different floors to limit the floors he would attempt. However, his boss finds that he breaks too many balls, so he suggests he find the strength using only two balls from each set. After some thought, the engineer decides to do the following. He will use the first ball for one attempt from the middle floor. If the ball breaks, it is certain that its strength is less than or equal to that corresponding to the middle floor. Therefore, he will use the second ball to check the strength sequentially starting from the first floor and trying each level successively. However, if it does not break when dropped from the middle floor, then he will exclude the bottom half of the building and continue in the same way for the upper half. That is, using the first ball again, he will try to find its strength starting from the middle level of the upper half of the building. Similarly, he will perform a binary search step if the first ball withstands the free fall or a linear search step after the first ball breaks.
Problem: Develop a program in one of the IOI languages that calculates the strength of a set of balls with the smallest number of attempts. No ball breaks on the ground floor.
INPUT DATA
The file balls.in has on the first line an integer (where ) representing the number of sets to be tested. Each of the lines that follow contains two integers , (where ) representing the levels of the building (excluding the ground floor) and the strength of the ball, respectively.
OUTPUT DATA
Your program should write lines to the file balls.out. Each line will have an integer indicating the minimum number of checks that must be made for each input line.
Example of Input - Output Files:
STDIN (balls.in)
2
7 2
7 5
STDOUT (balls.out)
3
3
Formatting: In both the input and the output, each line terminates with a newline
character.
Maximum execution time: 1sec.
Comments