Suspension Bridges

Photo by Bertbau, cc-sa
4.0 int

Mountain villages like to attract tourists by building suspension bridges, such as the one depicted here in the Harz Mountains in Germany. These bridges allow adventurously-inclined people to seek their thrills by crossing over deep gorges. To make sure that everyone gets just the right amount of excitement, the sag at the deepest point of the bridge should be significant relative to the distance the bridge covers.

Given the distance between the anchor points where the bridge is attached, and given a desired amount of sag, compute how long each of the cables holding the suspension bridge needs to be!

To help you solve this task, here is some background: A
free-hanging suspension bridge will take on the form of a
catenary curve (*catena* is Latin for
chain), just like a free-hanging chain between two poles. Given
the horizontal distance $d$ between two anchor points and the
desired amount $s$ the
cable is sagging in the center, there exists a positive
parameter $a$ such that
$a + s = a \cdot \cosh
\left(\frac{d}{2 a}\right)$. The length of the cable is
then given by $\ell (a,d) = 2 a
\cdot \sinh \left(\frac{d}{2 a}\right)$.

The functions $\sinh $ and $\cosh $ denote the hyperbolic sine and hyperbolic cosine, respectively, which are defined as follows:

$ \sinh x = \dfrac {e^ x - e^{-x}}{2} $ |
$ \cosh x = \dfrac {e^ x + e^{-x}}{2} $ |

The input consists of a single test case with two space-separated integers $d$ and $s$ given on a single line such that $0 < d \le 1\, 000$ and $0 < s \le 1\, 000$. The number $d$ denotes the distance between the anchor points and $s$ is the desired sag at the center of the bridge. More precisely, the “sag” here is the vertical distance between the cable’s lowest point in the center and the horizontal line formed by the $2$ anchor points on either side of the gorge.

Output the length of cable needed to cover the distance between the anchor points to achieve the desired sag. Your answer should be correct within an absolute error of $10^{-4}$.

Sample Input 1 | Sample Output 1 |
---|---|

400 40 |
410.474747252 |