# 描述

As we know, DreamGrid is a master of planning algorithm. Recently, a new type of autonomous car appears in Gridland. With the shape of a circle, the car can move in any direction. Being interested in this car, DreamGrid decides to design a specific path planning algorithm for it. Here is the first case he wants to solve.

Consider two cars on the two-dimensional plane with the same radius of $r$. We now want to move the center of the first car from $(0, 0)$ to $(d, 0)$, where $d$ is positive. The second car, starting its move with its center located at $(2r, 0)$, can be considered as an obstacle moving towards the positive direction of the x-axis with a constant speed of $v$. Luckily, after installing a new engine, the first car can move twice as fast as the obstacle car, which means the maximum speed of the first car can be $2v$.

DreamGrid wants to know the shortest time needed to move the first car to the end point without colliding with the second car. That is to say, before arriving at the end point, the circle representing the first car can’t intersect with (but can be tangent to) the circle representing the second car.

As DreamGrid is too busy, you are asked to solve this simple problem for him. Of course, if you successfully solve this problem, you will get a brand-new autonomous car in the Gridland!

## Input

There are multiple test cases. The first line of the input is an integer $T$($1 \le T \le 1000$), indicating the number of test cases. For each test case:

The only line contains three real numbers $v, r, d$($1 \le v, r \le 10, 1 \le d \le 100$) with at most two digits after the decimal point, indicating the radius of the car, the speed of the obstacle car and the distance between the start point and end point.

## Output

For each test case output one line, indicating the shortest time for the first car to arrive the end point without colliding with the second car. Your answer will be considered correct if and only if the absolute error or relative error of your answer is less than $10 ^ {-6}$.

# 思路

• 首先，很容易想到，让$A$圆紧跟着$B$圆做速度为$v$的匀速直线运动一定是合法的，用时为$\frac{d}{v}$，这是答案的上界。

• 比较自然的，我们想到可以让$A$圆保持与$B$圆相切，从$B$圆上方滚过去，滚动到某一个角度以后，再直线运动到终点。再简化一下，只保留$A$, $B$两圆的圆心，仍然记为$A$, $B$。

• 第一部分的运动轨迹：假设过去了时间$t$
• $B$点方程很好写：
$$\begin{cases} x = 2 r + v t \\ y = 0 \end{cases}$$
• $A$点的有点烦，运动分解为紧随$B$点的速率为$v$的匀速直线运动，以及以$B$点为圆心，半径为$2r$的变速率圆周运动。
记$α$为$AB$连线与$x$轴负方向的夹角，定义域为$[0,π]$
$A$点：
$$\begin{cases} x = 2 r + v t - 2 r \cos α\\ y = 2r \sin α \end{cases}$$
• 似乎有点眼熟啊，这玩意不是个摆线吗。嘤嘤嘤，不想做曲线积分算摆线长度，换个思路用$α$表示一下时间$t$。

• 如图，假设某一时刻，$AB$连线与$x$轴负方向的夹角为$β$，此时$A$, $B$相对运动关系如下，$V_t$是$A$在圆周上的切向速度，$V_x$和$V_y$是$V_t$的分解。

列个方程组
$$\begin{cases} V_x = V t \sin β \\ V_y = V t \cos β \\ (V_x + v) ^ 2 + V_y ^ 2 = (2 v) ^ 2 \end{cases}$$
解得 $V_t = v(\sqrt{\sin^2 β + 3} - \sin β)$

• 所以 $$t = \int_{0}^{α} \frac{2 r}{v(\sqrt{\sin^2 β + 3} - \sin β)} dβ$$
这个积分没有初等解，我们可以掏出 Wavator 的simpson板子。

• 所以第一部分的方程推完了，嘤嘤嘤。

• 第二部分就比较easy了，用时非常显然，即为$\frac{\sqrt{(d - x) ^ 2 + y ^ 2}}{2 v}$。下面的关键就在于确定两部分之间的分界点$α$。显然，分界点$α$必然在$[π/2, π]$之间，是摆线下降段的某个位置，很容易想到可以二分去做。

• 如何判断某一个$α$是否可行？我们可以在运动模式变化瞬间，取一个微元$Δt$判断一下$AB$之间的距离是否会变小。设$(x, y)$为该时刻$A$点坐标：
$$β = \arctan{(\frac{y}{d - x})}$$
$$Δ = (x - (2 r + v t)) \cdot (2 v \cos β - v) - (y - 0) \cdot 2 v \cos β$$

• 最终答案即为$\frac{\sqrt{(d - x) ^ 2 + y ^ 2}}{2 v} + t$
• 要注意的是，如果摆线一个周期的横坐标长度已经超过了$d$，直接输出$\frac{d}{v}$。
• 缅怀一下曾经的PHO打铁时光。

0%