No.450 ベー君のシャトルラン
タグ : / 解いたユーザー数 279
作問者 :
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
This problem is the Day 1 problem of Advent Calendar Contest 2016.
Problem Statement
Bee-kun the bee loves shuttle runs and looks forward to his school's physical fitness test every year.
One day, in order to improve his shuttle run record, Bee-kun came up with the following training method.
- Find a train on the left running rightward at speed $v_l$ [m/s], and a train on the right running leftward at speed $v_r$ [m/s].
- At this moment, the two trains face each other and are a distance $d$ [m] apart.
- At $t = 0$, Bee-kun starts from the front of the left train, heading right at speed $w$ [m/s].
- When he reaches the front of the right train, he touches it and turns back to the left.
- When he reaches the front of the left train, he touches it and turns back to the right.
- He repeats steps 4-5 until the two trains pass each other, and then finishes.
After finishing the training, Bee-kun wanted to know how far he had traveled.
Calculate the total distance traveled [m] for Bee-kun.
Note that:
- Bee-kun moves faster than the two trains,
- the positions of the two trains can be represented on the x-axis, and all other spatial distances are regarded as 0,
- Bee-kun moves parallel to the ground, and
- the time taken to touch is negligible.
Input
$v_l$ $v_r$ $d$ $w$
$ 1 \leq v_l, v_r \leq 10^9, v_l, v_r \in \mathbb{N} $
$ 1 \leq d \leq 10^9, d \in \mathbb{N}$
$ 1 \leq w \leq 10^9, w \in \mathbb{N} $
$ \max \{ v_l, v_r \} < w $
Output
Output Bee-kun's total distance traveled [m]. Print a newline at the end.
The output is accepted if the absolute error or relative error is at most $10^{−6}$.
Sample
Sample 1
Input
1 1 6 2
Output
6
This is the initial state.
When he touches the right train for the first time, Bee-kun has moved 4 [m].
When he turns back and touches the left train, Bee-kun has moved $\frac{4}{3}$ [m].
Since this repeats, the answer is $\sum_{n=0}^{\infty} \frac{4}{3^n} = 6$.
Sample 2
Input
1 3 12 7
Output
21
Sample 3
Input
90 568 5019 870
Output
6636.0638297
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。