409232: GYM103463 L Line problem

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. Line problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

We have learned your team is good at geometry problems. So we ask you a simple problem.

Now you have two segments in a $$$2$$$-dimensional plane, you should tell us the length of the intersection of two line segments.

What you need to pay attention to is, if these two line segments intersect at one point, we consider their intersecting length to be $$$0$$$.

Input

There are several test cases.

The first line contains a single integer $$$T(1 \leq T \leq 10^3)$$$, denoting the number of test cases. Then follow all the test cases.

The first line contains four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$$$$(-10^{9} \leq x_1, y_1, x_2, y_2 \leq 10^{9})$$$, representing the two points of the first line segment.

The second line contains four integers $$$x_3$$$, $$$y_3$$$, $$$x_4$$$, $$$y_4$$$$$$(-10^{9} \leq x_3, y_3, x_4, y_4 \leq 10^{9})$$$, representing the two points of the second line segment.

Output

For each test case, print the length of the intersection of two line line segments.

Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$.

Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$$$.

ExampleInput
2
0 0 3 3
1 1 2 2
0 0 1 1
1 1 2 2
Output
1.41421356237309514547
0.00000000000000000000

加入题单

算法标签: