#P16578. [GKS 2016 #A] Jane's Flower Shop

    ID: 16551 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>数学2016二分Special JudgeGoogle Kick Start

[GKS 2016 #A] Jane's Flower Shop

题目描述

Jane plans to open a flower shop in the local flower market. The initial cost includes the booth license, furnishings and decorations, a truck to transport flowers from the greenhouse to the shop, and so on. Jane will have to recoup these costs by earning income. She has estimated how much net income she will earn in each of the following MM months.

Jane wants to predict how successful her flower shop will be by calculating the IRRIRR (Internal Rate of Return) for the MM-month period. Given a series of (time, cash flow) pairs (i,Ci)(i, C_i), the IRR is the compound interest rate that would make total cash exactly 00 at the end of the last month. The higher the IRR is, the more successful the business is. If the IRR is lower than the inflation rate, it would be wise not to start the business in the first place.

For example, suppose the initial cost is 10,00010,000 and the shop runs for 33 months, with net incomes of 3,0003,000, 4,0004,000, and 5,0005,000, respectively. Then the IRR rr is given by:

$$-10000 \cdot (1 + r)^3 + 3000 \cdot (1 + r)^2 + 4000 \cdot (1 + r) + 5000 = 0$$

In this case, there is only one rate (8.8963%\approx 8.8963\%) that satisfies the equation.

Help Jane to calculate the IRR for her business. It is guaranteed that 1<r<1-1 < r < 1, and there is exactly one solution in each test case.

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case starts with a positive integer M{M}: the number of months that the flower shop will be open. The next line contains M+1{M} + 1 non-negative integers Ci{C}_i (0iM0 \le i \le M). Note that C0{C_0} represents the initial cost, all the remaining Ci{C_i}s are profits, the shop will always either make a positive net profit or zero net profit in each month, and will never have negative profits.

输出格式

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy is a floating-point number: the IRR of Jane's business. yy will be considered correct if it is within an absolute or relative error of 10610^{-6} of the correct answer.

3
2
200 100 100
3
10000 3000 4000 5000
5
3000 100 100 100 100 100
Case #1: 0.000000000000
Case #2: 0.088963394693
Case #3: -0.401790748826

提示

In sample case #11, the IRR is 00, Jane just paid back all the money and no interest.

Sample case #22 and #33 will only appear in large dataset.

Limits

1T1001 \le T \le 100.

C0>0{C_0} > 0.

0Ci1,000,000,0000 \le {C_i} \le 1,000,000,000.

Small dataset (Test set 1 - Visible)

1M21 \le {M} \le 2.

Large dataset (Test set 2 - Hidden)

1M1001 \le {M} \le 100.