PRUBALL - Esferas

no tags 

Balls

The classic Two Glass Balls brain-teaser is often posed as: "Given two identical glass spheres, you would like to determine the lowest floor in a 100-story building from which they will break when dropped. Assume the spheres are undamaged when dropped below this point. What is the strategy that will minimize the worst-case scenario for number of drops?" Suppose that we had only one ball. We'd have to drop from each floor from 1 to 100 in sequence, requiring 100 drops in the worst case. Now consider the case where we have two balls. Suppose we drop the first ball from floor n. If it breaks we're in the case where we have one ball remaining and we need to drop from floors 1 to n-1 in sequence, yielding n drops in the worst case (the first ball is dropped once, the second at most n-1 times). However, if it does not break when dropped from floor n, we have reduced the problem to dropping from floors n+1 to 100. In either case we must keep in mind that we've already used one drop. So the minimum number of drops, in the worst case, is the minimum over all n. You will write a program to determine the minimum number of drops required, in the worst case, given B balls and an M-story building.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. Each data set consists of a single line containing three (3) decimal integer values: the problem number, followed by a space, followed by the number of balls B, (1 ≤ B ≤ 50), followed by a space and the number of floors in the building M, (1 ≤ M ≤ 1000).

Output

For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the minimum number of drops needed for the corresponding values of B and M.

Sample Input

4

1 2 10

2 2 100

3 2 300

4 25 900

Sample Output

1 4

2 14

3 24

4 10


hide comments
(^@_^@): 2015-04-02 15:15:59

@Richard but in qes its clearly mentioned that for 1 ball 100floor ans is 100
i got AC without any assumption

(^@_^@): 2015-03-31 16:57:39

if any one can tell the ans for 2 balls & 2 floor then it would be more clear

Josef Ziegler: 2010-06-29 15:32:50

@Mahesh Chandra Sharma. No.

EDIT: I got AC without assuming this ;)

Last edit: 2010-07-04 20:37:12
Mahesh Chandra Sharma: 2010-06-29 14:13:36

should we assume that there will always be a floor from where when dropped ball will break?

Reborn In Fire...: 2010-05-12 06:13:42

since i've done it using one method I assumed was correct, can anyone tell me how is the mathematical proof derived, or see my submission(if you can) and tell another method??

EDIT: well, i discussed this with one of my friends, and we came on case of 1 ball and 100 floors. He said the answer should be 100 tries, and i too agreed. But now I checked it with my ACC program, and my program's answer is 99!! Please help me!!

Another EDIT in .5 mins: if Richard Cocks is right, then thanks!!!

Last edit: 2010-05-17 12:43:11
Richard Cocks: 2010-04-24 11:04:48

From description, "We'd have to drop from each floor from 1 to 100 in sequence, requiring 100 drops in the worst case". Surely you could drop it 99 times on floors 1 to 99. If it does not break on any of those you know it must break when dropping from floor 100. If it does not then there is no solution, the problem is to find the lowest floor at which it does not break, not the highest floor at which it survives. There must be the assumption it will break when dropped at the highest story?

:D: 2010-04-24 10:15:51

I agree with Oleg, I skipped the analisys to not spoil the problem for myself.

Also, Prelude & Nostalgia, I have no idea what are you talking about :)

Ravi Kiran: 2010-04-24 06:22:58

Just follow the problem description well and let code decide the answers for you! :)


Added by:Alvaro Javier Medina Balboa
Date:2010-04-23
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C++ 4.3.2 CPP JAVA