Cookie Farms
InterviewTime limit5sMemory limit512 MB
Starting at 2 cookies per second, decide how many farms that cost C and add F each to buy before waiting until X cookies are held.
Problem
You start with 0 cookies. Clicking a giant cookie earns you 2 cookies per second. Whenever you hold at least cookies, you may buy a cookie farm. Each farm costs cookies and raises your production by cookies per second.
You win the moment you hold cookies that you have not spent on farms. Compute how long winning takes if you play the best possible strategy.
Cookies accumulate continuously. After 0.1 seconds you have 0.2 cookies, and after seconds you have cookies. Buying a farm takes no time, and you may buy any number of farms.
Input
The first line contains the number of test cases . Each of the next lines contains three space-separated real numbers , and , with the meanings given above.
Each of , and is written as at least one digit, then a decimal point, then one to five digits. No number has a leading zero.
Output
For each test case print one line in the form Case #x: y, where is the test case number starting from 1 and is the minimum number of seconds needed to hold cookies.
Print rounded to exactly seven decimal places, keeping trailing zeros. The judge compares the output string exactly. Every answer in the input data sits far from a rounding boundary, so double precision arithmetic produces the same digits.
Hint
Whether one more farm pays off depends only on your current production rate. As the rate grows, the time needed to earn a farm shrinks slowly, while the time the farm saves shrinks faster. Once buying stops paying off, it never pays off again.