Hide

Problem I
Line Segment Distance

Input

The first line of input contains an integer $n$ ($n \leq 10000$) giving the number of test cases. Then follow $n$ lines each containing 8 integers $x_1\ y_1\ x_2\ y_2\ x_3\ y_3\ x_4\ y_4$, indicating a line segment from $(x_1, y_1)$ to $(x_2, y_2)$, and a line segment from $(x_3, y_3)$ to $(x_4, y_4)$. Coordinates have absolute value at most 10000.

Output

For each test case, output the distance between the two line segments with 2 decimals of precision.

Sample Input 1 Sample Output 1
5
-10 0 10 0 0 -10 0 10
-10 0 10 0 -5 0 5 0
1 1 1 1 1 1 2 1
1 1 1 1 2 1 2 1
1871 5789 216 -517 189 -1518 3851 1895
0.00
0.00
0.00
1.00
713.86

Please log in to submit a solution to this problem

Log in