Orig Description
Constellation
Problem
You are searching for a constellation from a photo of the night sky. The photo always includes exactly one figure of the same shape, orientation, and size as the constellation you are looking for. However, the photo may contain extra stars that are not part of the constellation.
For example, the constellation in Figure 1 is included in the photo in Figure 2 (indicated by the enclosed circle). When the coordinates of the stars in the given constellation are moved parallel to the x-axis by 2 and parallel to the y-axis by −3, they match the position in the photo.
Write a program that, given the shape of the constellation you are looking for and the positions of the stars in the photo, finds the amount by which to move the constellation in order to match the positions in the photo.
Figure 1: Constellation you are looking forFigure 2: Photo of the night sky
Input
The input consists of multiple datasets. Each dataset is given in the following format.
The first line of the input contains the number of stars m that make up the constellation you are looking for. The following m lines contain integers separated by a space that indicate the x and y coordinates of the m stars that make up the constellation you are looking for. The (m+2)-th line contains the number of stars n in the photo. The following n lines contain integers separated by a space that indicate the x and y coordinates of the n stars in the photo.
All m stars that make up the constellation are at different positions. All n stars in the photo are at different positions. 1 ≤ m ≤ 200, 1 ≤ n ≤ 1000. The x and y coordinates of the stars are all between 0 and 1000000.
If m is 0, it indicates the end of the input. There will be no more than 5 datasets.
Output
For each dataset, write a single line of output consisting of two integers separated by a space. The first integer indicates the amount by which to move the constellation parallel to the x-axis, and the second integer indicates the amount by which to move the constellation parallel to the y-axis in order to match the positions in the photo.
Sample Input
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
Sample Output
2 -3
-384281 179674
Sample Input 1 corresponds to the figure above.
The problem statement and test data are provided by the Information Olympiad Japan Committee.
Extracted Specification
An integer m (1 ≤ m ≤ 200), followed by m lines each containing two integers representing coordinates (0 ≤ x, y ≤ 1000000). Followed by an integer n (1 ≤ n ≤ 1000), followed by n lines each containing two integers representing coordinates (0 ≤ x, y ≤ 1000000). The input ends when m is 0. There will be no more than 5 datasets.
### Example Input:
```
5
8 5
6 4
4 3
7 10
0 10
10
10 5
2 7
9 7
8 10
10 2
1 2
8 1
6 7
6 0
0 9
5
904207 809784
845370 244806
499091 59863
638406 182509
435076 362268
10
757559 866424
114810 239537
519926 989458
461089 424480
674361 448440
81851 150384
459107 795405
299682 6700
254125 362183
50795 541942
0
```
### Function Signature:
Write a function f(datasets) that takes in the input.
```python
def f(datasets: List[Tuple[int, List[Tuple[int, int]], int, List[Tuple[int, int]]]]):
'''
datasets: a list of tuples where each tuple contains:
- an integer
- a list of tuples of integers
- an integer
- a list of tuples of integers
'''
```
Test Case Generator
Sure, here is a test case generator for the "Constellation" problem:
```python
import random
def tcgen():
datasets = []
for _ in range(random.randint(1, 5)): # there will be no more than 5 datasets
m = random.randint(1, 200) # 1 ≤ m ≤ 200
constellation = set()
while len(constellation) < m:
x = random.randint(0, 1000000)
y = random.randint(0, 1000000)
constellation.add((x, y))
constellation = list(constellation)
n = random.randint(m, 1000) # 1 ≤ n ≤ 1000, n should be at least m
photo = set()
added_constellation = False
while len(photo) < n:
if not added_constellation and random.random() < 0.5:
# Add the constellation by shifting it randomly
dx = random.randint(-100000, 100000)
dy = random.randint(-100000, 100000)
for (x, y) in constellation:
photo.add((x + dx, y + dy))
added_constellation = True
else:
x = random.randint(0, 1000000)
y = random.randint(0, 1000000)
photo.add((x, y))
photo = list(photo)
datasets.append((m, constellation, n, photo))
return datasets
def format_dataset(dataset):
m, constellation, n, photo = dataset
result = []
result.append(str(m))
for x, y in constellation:
result.append(f"{x} {y}")
result.append(str(n))
for x, y in photo:
result.append(f"{x} {y}")
return "\n".join(result)
# Generate the test cases
test_cases = tcgen()
# Print the test cases in the required format
for dataset in test_cases:
formatted_dataset = format_dataset(dataset)
print(formatted_dataset)
print() # separate datasets with a blank line
```
This script generates multiple datasets for the "Constellation" problem. Each dataset contains the number of stars in the constellation and their coordinates, followed by the number of stars in the photo and their coordinates. It ensures that all coordinates are unique and within the specified range.
The `format_dataset` function formats a single dataset into the required string format for input. The `tcgen` function generates the datasets and prints them. Each dataset is separated by a blank line for clarity.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
m = int(fh.readline().strip())
if m == 0:
break
constellation = []
for _ in range(m):
x, y = map(int, fh.readline().strip().split())
constellation.append((x, y))
n = int(fh.readline().strip())
photo = []
for _ in range(n):
x, y = map(int, fh.readline().strip().split())
photo.append((x, y))
datasets.append((m, constellation, n, photo))
return datasets
# Example usage:
# with open('input.txt', 'r') as fh:
# datasets = extract_arguments(fh)
# for data in datasets:
# m, constellation, n, photo = data
# # process each dataset