Cookie Farms
InterviewTime limit5sMemory limit512 MB
Decide how many cookie farms to buy before waiting so the time to hold X cookies is as short as possible.
Problem
You start with 0 cookies and earn 2 cookies per second by clicking a giant cookie. Whenever you hold at least cookies, you can buy a cookie farm. Each farm costs cookies and adds cookies per second to your production.
You win the moment you hold cookies that you have not spent on farms. Find how long winning takes under the best possible strategy.
Cookies accumulate continuously. 0.1 seconds after the start you have 0.2 cookies, and seconds after the start you have cookies.
For , , the best strategy plays out like this.
- You start with 0 cookies and a production of 2 cookies per second.
- After 250 seconds you hold cookies and buy a farm that produces cookies per second.
- After the purchase you hold 0 cookies and produce 6 cookies per second.
- The next farm also costs 500 cookies, which you can afford after about 83.3333333 seconds.
- After the second purchase you hold 0 cookies and produce 10 cookies per second.
- The farm after that also costs 500 cookies, which you can afford after 50 seconds.
- After the third purchase you hold 0 cookies and produce 14 cookies per second.
- A fourth farm would also cost 500 cookies, but buying it is worse than waiting. Waiting for cookies takes about 142.8571429 seconds.
The total time is seconds.
Input
The first line contains the number of test cases . Each of the next lines contains three space separated real numbers , , and .
, , and each consist of an integer part of one or more digits, a decimal point, and a fractional part of one to five digits. The integer part has no 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.
Round to seven decimal places and always print seven digits after the decimal point, padding with zeros.
Hint
Whether one more farm pays off depends on your current production per second. Once buying one more farm stops paying off, every later farm is a loss as well, so buy farms only while they still pay off.