#P17420. [ICPC 2018 Xuzhou R] Rikka with Consistency

    ID: 19922 远端评测题 12000ms 512MiB 尝试: 0 已通过: 0 显示难度提高+/省选− 上传者: 标签>2018Special Judge图论建模最短路ICPC

[ICPC 2018 Xuzhou R] Rikka with Consistency

Problem Description

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 nn segments in the XX-HH plane. The ii-th segment connects the points (i−1,hi−1)(i - 1, h_{i - 1}) and (i,hi)(i, h_i), and h0=hn=0h_0 = h_n = 0 are known. This figure is a topographic map showing the whole trip from Beijing to Moscow and its HH 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 XX-HH plane is (0,0)(0, 0); Consistency, the guy who will replace Rikka, is in Moscow which is located at (n,0)(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 Format

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

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

The second line contains (n+1)(n + 1) integers h0,h1,⋯ ,hnh_0, h_1, \cdots, h_n (0≤hi≤500 \le h_i \le 50), satisfying h0=hn=0h_0 = h_n = 0.

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

Output Format

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−910^{-9}. Formally, let your answer be aa, and Rikka's answer be bb. Your answer is considered correct if ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a - b|}{\max(1, |b|)} \le 10^{-9}.

2
4
0 1 1 2 0
4
0 2 1 3 0
12.128990204491960
22.313624568639947