405613: GYM102012 C Rikka with Consistency

Memory Limit:1024 MB Time Limit:8 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Rikka with Consistencytime limit per test8 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard output

On the way to the Moscow, Rikka knows someone will replace her. Who is the guy? A devil to get in touch with her dark side, or an angel to rinse the shadow off her mind? However, Rikka knows that her successor has a special name, whose meaning in Chinese is Consistency. The process of replacement is so wonderful and sentimental, which is what you all must know.

Now, the only road from Beijing to Moscow is described as a broken line with $$$n$$$ segments in the $$$X$$$-$$$H$$$ plane. The $$$i$$$-th segment connects the points $$$(i - 1, h_{i - 1})$$$ and $$$(i, h_i)$$$, and $$$h_0 = h_n = 0$$$ are known. This figure is a topographic map showing the whole trip from Beijing to Moscow and its $$$H$$$ axis indicates the altitude. The distance of a path between two points is the length of the broken line between their corresponding points in the map.

At the outset of the trip, Rikka is in Beijing whose location in the $$$X$$$-$$$H$$$ plane is $$$(0, 0)$$$; Consistency, the guy who will replace Rikka, is in Moscow which is located at $$$(n, 0)$$$. Consistency always maintains consistent academic standards, a consistent life level, a consistent height of perspective and the altitude as what Rikka owns. This is why their heights are the same yesterday, today and forever.

Now Rikka wants you to calculate the minimum total distance they need (which is the total length of paths that Rikka and Consistency travel along). By the time that Rikka arrives in Moscow and Consistency arrives in Beijing as well, their replacement will be finished (and this is the ending which is also a new beginning).

Input

The input contains several test cases, and the first line contains a single integer $$$T$$$ ($$$1 \le T \le 500$$$), the number of test cases.

For each test case, the first line contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$), the number of segments.

The second line contains $$$(n + 1)$$$ integers $$$h_0, h_1, \cdots, h_n$$$ ($$$0 \le h_i \le 50$$$), satisfying $$$h_0 = h_n = 0$$$.

The input guarantees that the paths for each test case always exist.

Output

For each test case, output a single line with a single number, the minimum total distance they need. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally, let your answer be $$$a$$$, and Rikka's answer be $$$b$$$. Your answer is considered correct if $$$\frac{|a - b|}{\max(1, |b|)} \le 10^{-9}$$$.

ExampleInput
2
4
0 1 1 2 0
4
0 2 1 3 0
Output
12.128990204491960
22.313624568639947

加入题单

算法标签: