#P10057. Line
Line
Problem Description
On a 2D plane, you are given two line segments and , which are parallel to the -axis and the -axis respectively.
You may choose one segment and translate it in any direction parallel to the coordinate axes (up, down, left, or right) by any distance. This is called one operation.
What is the minimum number of operations needed to make the two segments intersect?
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
For each test case:
- One line contains eight positive integers , representing the coordinates of .
Output Format
For each test case:
- Output one integer per line, the minimum number of operations.
3
1 1 2 1 1 1 1 2
1 1 2 1 1 2 1 3
2 1 3 1 1 2 1 3
0
1
2
Hint
[Sample 1 Explanation]
- For the first test case, the two segments already intersect, so no operation is needed.
- For the second test case, one feasible plan is: translate segment upward by unit.
- For the third test case, one feasible plan is: translate segment upward by unit, then translate segment rightward by unit.
[Constraints]
Let .
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| The answer is guaranteed to be at most | |||
| None |
For of the testdata, , , , , , .
Translated by ChatGPT 5