Orig Description
Score : 300 points
Problem StatementThere are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation:
Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we optimally choose p and q.
Constraints
1 \leq N \leq 50
|x_i|, |y_i| \leq 10^9
If i \neq j, x_i \neq x_j or y_i \neq y_j.
All values in input are integers.
InputInput is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N
OutputPrint the minimum total cost required to collect all the balls.
Sample Input 12
1 1
2 2
Sample Output 11
If we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by collecting them in the order (1, 1), (2, 2).
Sample Input 23
1 4
4 6
7 8
Sample Output 21
If we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by collecting them in the order (7, 8), (4, 6), (1, 4).
Sample Input 34
1 1
1 2
2 1
2 2
Sample Output 32
Extracted Specification
An integer N (1 ≤ N ≤ 50), representing some quantity or size.
N pairs of integers (x, y), where each integer is between -10^9 and 10^9.
### Example Input:
```
3
1 4
4 6
7 8
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, int]]):
'''
inputs: a list of tuples, where each tuple contains two integers
'''
```
Test Case Generator
Sure, here is a Python test case generator for the given problem statement:
```python
import random
def tcgen():
N = random.randint(1, 50)
balls = []
x_coords = set()
y_coords = set()
for _ in range(N):
while True:
x = random.randint(-10**9, 10**9)
y = random.randint(-10**9, 10**9)
# Ensure unique x or y coordinates as per problem constraints
if x not in x_coords and y not in y_coords:
x_coords.add(x)
y_coords.add(y)
balls.append((x, y))
break
return N, balls
# Example usage
N, balls = tcgen()
print(N)
for x, y in balls:
print(x, y)
```
This generator ensures that:
1. `N` is chosen randomly between 1 and 50.
2. Each ball's coordinates `(x, y)` are chosen such that `|x|` and `|y|` each can be as large as \(10^9\).
3. Coordinates of each ball are unique in terms of either `x` or `y` (ensuring `x_i != x_j` or `y_i != y_j` for `i != j`).
You can use the `tcgen` function to generate test cases for your problem. Each call to `tcgen` will produce a new set of test data adhering to the constraints specified.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
coordinates = []
for _ in range(N):
x, y = map(int, fh.readline().strip().split())
coordinates.append((x, y))
return N, coordinates
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, coordinates = extract_arguments(fh)
# f(N, coordinates)