No.1993 Horse Racing
Problem Statement
At the ranch run by Core-san, $N$ horses numbered $1, 2, \dots, N$ are raised.
Core-san decided to have these $N$ horses race according to the following rules.
All horses start running simultaneously from a common starting point and race to a common finish point.
The race course is a straight line, and the length from the starting point to the finish point is $1000$ meters.
When this race was held, the following held for $i = 1, 2, \dots, N-1$.
When horse $i$ finished, horse $(i + 1)$ was running $A_{i}$ meters behind horse $i$.
When horse $1$ finished, how many meters behind horse $1$ was horse $N$ running?
Here, assume that each horse always runs at a constant speed.
Constraints
$2 \leq N \leq 100$
$0 \leq A_{i} \leq 10$ $(1 \leq i \leq N-1)$
All inputs are integers.
Input
The input is given in the following format.
$N$
$A_{1}$ $A_{2}$ $\cdots$ $A_{N-1}$
The $1$st line contains $N$.
The $2$nd line contains $A_{1}, A_{2}, \dots, A_{N-1}$ in this order, separated by single spaces.
Output
Print the answer on $1$ line, followed by a newline.
The output is judged as correct if its absolute or relative error from the expected answer is at most $10^{−6}$.
Sample
Sample 1
Input
3 10 10
Output
19.9
When horse $1$ has finished running $1000$ meters, horse $2$ has run $990$ meters, so
we can see that the speed of horse $2$ is $990 / 1000$ times that of horse $1$.
Similarly, the speed of horse $3$ is $990 / 1000$ times that of horse $2$, so
when horse $1$ has finished running $1000$ meters, horse $3$ is running
$\displaystyle 1000 - 1000 \times \dfrac{990}{1000} \times \dfrac{990}{1000} = 19.9$
meters behind horse $1$.
Sample 2
Input
11 1 2 3 4 5 6 7 8 9 10
Output
53.6979931256464667570490112
Even if the output value does not exactly match the expected answer, it is judged as correct if its absolute or relative error from the expected answer is at most $10^{−6}$.
When using std::cout in C++, be careful about the number of digits displayed in the output value.
Sample 3
Input
8 0 0 0 0 0 0 0
Output
0
All $8$ horses run at the same speed.
Sample 4
Input
2 10
Output
10
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
MasKoaTS