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
ab_biswas09: 2019-03-22 11:08:01

O(b*m*m) >> 0.01 s
O(mlogK) >> 0.00 s

mammadbastar: 2019-02-28 11:18:47

ba tashakor az ostade khoobam kianoosh abbasi

masters_abh: 2018-10-17 12:21:24

100th :)

aegon_c: 2018-05-08 09:36:07

refer to this article
https://brilliant.org/wiki/egg-dropping/?quiz=egg-dropping#

mkfeuhrer: 2016-07-12 17:55:10

c++5.1 ->WA
c++4.3.2 -> AC! crazyy stuff!

Archit Jain: 2016-03-25 09:36:19

nice one

Vivek Mangal: 2016-02-19 19:59:13

Simple egg drooping problem.

Utkarsh Kumar: 2016-01-24 09:56:33

Weak test cases.

coppercastle: 2015-09-19 07:42:02

N egg problem

anando_du: 2015-09-13 14:50:58

dropping egg puzzle O(ball*storied^2) solution


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