Problem p00447 - Generation 3

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), representing some quantity or size.  
A list of \(m\) tuples, each containing two integers (0 ≤ integer ≤ 1e6), representing some coordinates.  
An integer \(n\) (1 ≤ \(n\) ≤ 1000), representing some other quantity or size.  
A list of \(n\) tuples, each containing two integers (0 ≤ integer ≤ 1e6), representing some other coordinates.  
If \(m\) is 0, it indicates the end of the input. 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
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, each containing:
        - an integer (1 ≤ m ≤ 200)
        - a list of m tuples, each containing two integers (0 ≤ integer ≤ 1e6)
        - an integer (1 ≤ n ≤ 1000)
        - a list of n tuples, each containing two integers (0 ≤ integer ≤ 1e6)
    '''
```

Test Case Generator

Sure, I can help you write a test case generator for the competitive programming problem "Constellation". Below is the Python code for the test case generator:

```python
import random

def generate_test_case():
    # Number of stars in the constellation (1 ≤ m ≤ 200)
    m = random.randint(1, 200)
    
    # Generate m unique stars for the constellation
    constellation_stars = set()
    while len(constellation_stars) < m:
        x = random.randint(0, 1000000)
        y = random.randint(0, 1000000)
        constellation_stars.add((x, y))
    
    constellation_stars = list(constellation_stars)
    
    # Number of stars in the photo (1 ≤ n ≤ 1000)
    n = random.randint(1, 1000)
    
    # Generate n unique stars for the photo, ensuring it includes the constellation
    photo_stars = set(constellation_stars)  # Start with constellation stars
    
    while len(photo_stars) < n:
        x = random.randint(0, 1000000)
        y = random.randint(0, 1000000)
        photo_stars.add((x, y))
    
    photo_stars = list(photo_stars)
    
    # Shuffle the photo stars to simulate randomness
    random.shuffle(photo_stars)

    return m, constellation_stars, n, photo_stars

def tcgen():
    test_cases = []
    
    for _ in range(random.randint(1, 5)):  # Generate between 1 and 5 datasets
        m, constellation_stars, n, photo_stars = generate_test_case()
        test_cases.append((m, constellation_stars, n, photo_stars))
    
    return test_cases

def print_test_case(tc):
    for m, constellation_stars, n, photo_stars in tc:
        print(m)
        for (x, y) in constellation_stars:
            print(x, y)
        print(n)
        for (x, y) in photo_stars:
            print(x, y)
    print(0)  # End of input

# Example usage:
test_cases = tcgen()
print_test_case(test_cases)
```

### Explanation:

1. **generate_test_case()**: This function generates a single test case.
    - It starts by generating `m` unique stars for the constellation.
    - Ensures the constellation is included within the photo, and then adds additional random stars to the photo until it reaches the desired number `n`.
  
2. **tcgen()**: This function generates a list of multiple datasets (between 1 and 5).
    - For each dataset, it calls `generate_test_case()` to create a complete dataset.
    - Returns the list of datasets.

3. **print_test_case()**: This function prints the generated test cases in the required format.
    - Iterates through each dataset and prints the number of stars in the constellation, followed by the coordinates of each star.
    - Then it prints the number of stars in the photo, followed by the coordinates of each star.
    - Finally, it prints `0` to indicate the end of input.

You can call `tcgen()` to generate the test cases and then use `print_test_case()` to print them in the format required by the problem statement.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        m = int(fh.readline().strip())
        if m == 0:
            break
        constellation = [tuple(map(int, fh.readline().strip().split())) for _ in range(m)]
        n = int(fh.readline().strip())
        photo = [tuple(map(int, fh.readline().strip().split())) for _ in range(n)]
        datasets.append((constellation, photo))
    return datasets

# Example usage
# if __name__ == "__main__":
#     input_path = sys.argv[1]
#     with open(input_path, 'r') as fh: 
#         datasets = extract_arguments(fh)
#         for constellation, photo in datasets:
#             f(constellation, photo)