QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 256 MB 總分: 100 可 Hack ✓

#15284. Distance between line segments

统计

Given four integer points $A, B, C, D$ on a plane, you need to find the distance between line segment $AB$ and line segment $CD$. Both line segments $AB$ and $CD$ may degenerate into a single point.

Input

Each test case contains multiple test data.

The first line of the input contains an integer $T$, representing the number of test cases. For each test case:

The input consists of a single line containing 8 integers $x_A, y_A, x_B, y_B, x_C, y_C, x_D, y_D$, describing the coordinates of the four points respectively.

Output

For each test case, output a single real number representing the shortest distance. The relative or absolute error should not exceed $10^{-9}$.

Examples

Input 1

6
0 0 1 1 1 0 2 1
0 0 1 1 2 2 3 3
0 0 0 100 100 0 200 300
0 0 0 100 50 50 100 50
-1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000
998 244 353 114 514 19 19 810

Output 1

0.7071067812
1.4142135624
100.0000000000
50.0000000000
2000000000.0000000000
0.0000000000

Subtasks

For all data, $1 \le T \le 10^5$, and each coordinate of the points is an integer in the range $[-10^9, 10^9]$. The coordinates of the points may coincide.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.