问题 G: Expected Distance

内存限制:512 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:1 解决:1

题目描述

Given two segments that are perpendicular to each other on a two-dimension Cartesian plane, you need to pick a point uniformly at random on each of them and calculate the expected Euclidean distance between the two picked points.

输入

The input contains multiple cases. The first line of the input contains a single integer T (1 ≤ T ≤ 1 000), indicating the number of test cases. For each case, each of the two lines contains four integers x1, y1, x2 and y2 (−1 000 ≤ x1, y1, x2, y2 ≤ 1 000), denoting a segment that connects (x1, y1) and (x2, y2). It is guaranteed that the two endpoints of each segment do not coincide, and that the two segments are perpendicular to each other.

输出

For each case, output a single real number, indicating the expected distance between the two randomly picked points. Your answer is acceptable if its absolute or relative error does not exceed 10−9 . Formally speaking, suppose that your output is a and the jury’s answer is b, your output is accepted if and only if |a−b| max(1,|b|) ≤ 10−9 .

样例输入 复制

1
0 0 1 0
0 0 0 1

样例输出 复制

0.765195716464212691

提示

In the sample case, the expected distance is R 1 0 R 1 0 p x 2 + y 2 dx dy = √ 2+ln(1+√ 2) 3 ≈ 0.765195716464212691.