P22354 [CodeChef] POINTMEE
提高
题目描述

Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are given N distinct points in a 2-D plane, numbered 1 through N. The X-coordinate of the points are $X_{1}, X_{2}, \ldots, X_{N}$ respectively and the Y-coordinates are $Y_{1}, Y_{2}, \ldots, Y_{N}$ respectively. Your goal is to make the location of all the N points equal to that of each other. To achieve this, you can do some operations.

In one operation, you choose an index i\;(1 ≤ i ≤ N) and a real number K and change the location of the i^{th} point in one of the following ways:
Set (X_{i}, Y_{i}) = (X_{i} + K, Y_{i})
Set (X_{i}, Y_{i}) = (X_{i}, Y_{i} + K)
Set (X_{i}, Y_{i}) = (X_{i} + K, Y_{i} + K)
Set (X_{i}, Y_{i}) = (X_{i} + K, Y_{i} - K)

Find the minimum number of operations to achieve the goal.

------ Input Format ------

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • Each test case contains three lines of input.
  • The first line contains a single integer N.
  • The second line contains $N space-separated integers X_{1}, X_{2}, \ldots, X_{N}$.
  • The third line contains $N space-separated integers Y_{1}, Y_{2}, \ldots, Y_{N}$.

------ Output Format ------

For each test case, print a single line containing one integer - the minimum number of operations to achieve the goal.

------ Constraints ------

$1 ≤ T ≤ 300$
$2 ≤ N ≤ 100$
$-10^{9} ≤ X_{i}, Y_{i} ≤ 10^{9}$
$(X_{i}, Y_{i}) \neq (X_{j}, Y_{j})$ if $(i \neq j)$
- Sum of $N$ over all test cases does not exceed $600$.

------ subtasks ------

Subtask #1 (100 points): original constraints

----- Sample Input 1 ------
2
3
0 1 -4
0 1 5
3
0 1 3
1 1 -1

----- Sample Output 1 ------
3
2

----- explanation 1 ------
Test case $1$ :
- In the first operation, you choose $i = 2$, and $K = - 1$ and apply the third type of operation. So the location of $2^{nd}$ point becomes $(1 - 1, 1 - 1) = (0, 0)$.

  • In the second operation, you choose $i = 3$, and $K = 4$ and apply the first type of operation. So the location of $3^{rd}$ point becomes $(- 4 + 4, 5) = (0, 5)$.

  • In the third operation, you choose $i = 3$, and $K = -5$ and apply the second type of operation. So the location of $3^{rd}$ point becomes $(0, 5 - 5) = (0, 0)$.

Hence after the above operations, the location of the given three points becomes equal to each other.

Test case $2$ :
- In the first operation, you choose $i = 1$ and $K = 1$ and apply the first type of operation. So the location of 1st point becomes $(0 + 1, 1) = (1, 1)$.

  • In the second operation, you choose $i = 3$, and $K = -2$ and apply the fourth type of operation. So the location of 3rd point becomes $(3 - 2, -1 - (-2)) = (1, 1)$.

Hence after the above operations, the location of the given three points becomes equal to each other.

输入格式

见题面

输出格式

见题面

样例输入
2 3 0 1 -4 0 1 5 3 0 1 3 1 1 -1
样例输出
3 2