#P8858. 折线
折线
Problem Description
In the first quadrant of the Cartesian coordinate system, there is a rectangular region with bottom-left corner at and top-right corner at . Inside the region there are a positive even number of integer lattice points. You need to find a polyline inside the region that starts from and ends at such that:
- Each segment of the polyline is parallel to the -axis or the -axis.
- The polyline must not pass through any of the given lattice points.
- The polyline divides the whole region into two parts, and the two parts contain the same number of given lattice points.
- The polyline has as few turning points as possible.
It can be proven that such a polyline always exists. You only need to output the number of turning points of a polyline that satisfies the constraints.
Note that the coordinates of turning points do not have to be integers.
Input Format
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains a positive even integer , the number of given lattice points.
Then follow lines. The -th line contains two positive integers , meaning the -th given lattice point is at .
Output Format
Output lines. Each line contains a positive integer, the number of turning points of a polyline satisfying the constraints.
3
4
1 1
1 2
4 1
4 2
6
1 2
1 3
2 1
2 2
2 3
3 2
12
1 3
2 2
2 3
2 4
3 1
3 2
3 4
3 5
4 2
4 3
4 4
5 3
2
3
4
Hint
Sample Explanation
For the first test case, one valid polyline is: $(0,0) \to (2.5,0) \to (2.5,10^{100}) \to (10^{100},10^{100})$. It has two turning points: and .
Constraints
| Test Point ID | Special Constraint | |
|---|---|---|
| None. | ||
| The answer is guaranteed to be no more than . | ||
| None. |
For all test cases, , , . It is guaranteed that is a positive even number, and within each test case, no two lattice points have the same coordinates.
Translated by ChatGPT 5