Problem p01292 - Generation 3

Orig Description

Problem J: Secret Operation
Mary Ice is a member of a spy group. She is about to carry out a secret operation with her colleague.
She has got into a target place just now, but unfortunately the colleague has not reached there yet. She
needs to hide from her enemy George Water until the colleague comes. Mary may want to make herself
appear in George’s sight as short as possible, so she will give less chance for George to find her.
You are requested to write a program that calculates the time Mary is in George’s sight before her colleague arrives, given the information about moves of Mary and George as well as obstacles blocking their
sight.
Read the Input section for the details of the situation.
Input
The input consists of multiple datasets. Each dataset has the following format:
Time R
L
MaryX1 MaryY1 MaryT1
MaryX2 MaryY2 MaryT2
...
MaryXL MaryYL MaryTL
M
GeorgeX1 GeorgeY1 GeorgeT1
GeorgeX2 GeorgeY2 GeorgeT2
...
GeorgeXM GeorgeYM GeorgeTM
N
BlockSX1 BlockSY1 BlockTX1 BlockTY1
BlockSX2 BlockSY2 BlockTX2 BlockTY2
...
BlockSXN BlockSYN BlockTXN BlockTYN
The first line contains two integers. Time (0 ≤ Time ≤ 100) is the time Mary's colleague reaches the
place. R (0 < R < 30000) is the distance George can see - he has a sight of this distance and of 45
degrees left and right from the direction he is moving. In other words, Mary is found by him if and only
if she is within this distance from him and in the direction different by not greater than 45 degrees from
his moving direction and there is no obstacles between them.
The description of Mary's move follows. Mary moves from (MaryXi, MaryYi) to (MaryXi+1, MaryYi+1)
straight and at a constant speed during the time between MaryTi and MaryTi+1, for each 1 ≤ i ≤ L - 1.
The following constraints apply: 2 ≤ L ≤ 20, MaryT1 = 0 and MaryTL = Time, and MaryTi < MaryTi+1
for any 1 ≤ i ≤ L - 1.
The description of George's move is given in the same way with the same constraints, following Mary's.
In addition, (GeorgeXj, GeorgeYj ) and (GeorgeXj+1, GeorgeYj+1) do not coincide for any 1 ≤ j ≤ M - 1. In other words, George is always moving in some direction.
Finally, there comes the information of the obstacles. Each obstacle has a rectangular shape occupying
(BlockSXk, BlockSYk) to (BlockTXk, BlockTYk). No obstacle touches or crosses with another. The number of obstacles ranges from 0 to 20 inclusive.
All the coordinates are integers not greater than 10000 in their absolute values. You may assume that, if
the coordinates of Mary's and George's moves would be changed within the distance of 10-6, the solution would be changed by not greater than 10-6.
The last dataset is followed by a line containing two zeros. This line is not a part of any dataset and should not be processed.
Output
For each dataset, print the calculated time in a line. The time may be printed with any number of digits after the decimal
point, but should be accurate to 10-4 .
Sample Input
50 100
2
50 50 0
51 51 50
2
0 0 0
1 1 50
0
0 0
Output for the Sample Input
50

Extracted Specification

An integer Time (0 ≤ Time ≤ 100).
An integer R (0 < R < 30000).
An integer L (2 ≤ L ≤ 20).
L triplets of integers MaryXi, MaryYi, MaryTi where (abs(MaryXi), abs(MaryYi) ≤ 10000) and (0 ≤ MaryTi ≤ Time).

An integer M (2 ≤ M ≤ 20).
M triplets of integers GeorgeXj, GeorgeYj, GeorgeTj where (abs(GeorgeXj), abs(GeorgeYj) ≤ 10000) and (0 ≤ GeorgeTj ≤ Time).

An integer N (0 ≤ N ≤ 20).
N quadruplets of integers BlockSXk, BlockSYk, BlockTXk, BlockTYk where (abs(BlockSXk), abs(BlockSYk), abs(BlockTXk), abs(BlockTYk) ≤ 10000).

Each dataset ends with a line containing two zeros.

### Example Input:
```
50 100
2
50 50 0
51 51 50
2
0 0 0
1 1 50
0
0 0
```

### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, int, int, List[Tuple[int, int, int]], int, List[Tuple[int, int, int]], int, List[Tuple[int, int, int, int]]]]):
    '''
    inputs: a list of tuples, where each tuple contains the following elements:
        Time: an integer
        R: an integer
        L: an integer
        MaryMoves: a list of L tuples, each tuple containing three integers
        M: an integer
        GeorgeMoves: a list of M tuples, each tuple containing three integers
        N: an integer
        Obstacles: a list of N tuples, each tuple containing four integers
    '''
```

Test Case Generator

Sure! Below is a Python function to generate test cases for the described problem "Secret Operation".

```python
import random

def generate_coordinates():
    return random.randint(-10000, 10000), random.randint(-10000, 10000)

def tcgen():
    datasets = []
    
    while True:
        # Time (0 ≤ Time ≤ 100)
        Time = random.randint(0, 100)
        # R (0 < R < 30000)
        R = random.randint(1, 29999)

        # Number of moves for Mary (2 ≤ L ≤ 20)
        L = random.randint(2, 20)
        Mary_moves = []
        MaryT = [0] + sorted(random.sample(range(1, Time), L - 1)) + [Time]
        for i in range(L):
            MaryX, MaryY = generate_coordinates()
            Mary_moves.append((MaryX, MaryY, MaryT[i]))

        # Number of moves for George (2 ≤ M ≤ 20)
        M = random.randint(2, 20)
        George_moves = []
        GeorgeT = [0] + sorted(random.sample(range(1, Time), M - 1)) + [Time]
        for i in range(M):
            GeorgeX, GeorgeY = generate_coordinates()
            George_moves.append((GeorgeX, GeorgeY, GeorgeT[i]))

        # Number of obstacles (0 ≤ N ≤ 20)
        N = random.randint(0, 20)
        obstacles = []
        for _ in range(N):
            BlockSX, BlockSY = generate_coordinates()
            BlockTX, BlockTY = generate_coordinates()
            obstacles.append((BlockSX, BlockSY, BlockTX, BlockTY))

        # Add generated data to the dataset
        dataset = {
            "Time": Time,
            "R": R,
            "Mary_moves": Mary_moves,
            "George_moves": George_moves,
            "obstacles": obstacles
        }
        datasets.append(dataset)

        # Randomly decide whether to stop generating more datasets
        if random.choice([True, False]):
            break

    return datasets

# Example usage
test_cases = tcgen()

# Printing the generated test cases in the format described
for tc in test_cases:
    print(f'{tc["Time"]} {tc["R"]}')
    print(len(tc["Mary_moves"]))
    for move in tc["Mary_moves"]:
        print(f'{move[0]} {move[1]} {move[2]}')
    print(len(tc["George_moves"]))
    for move in tc["George_moves"]:
        print(f'{move[0]} {move[1]} {move[2]}')
    print(len(tc["obstacles"]))
    for obstacle in tc["obstacles"]:
        print(f'{obstacle[0]} {obstacle[1]} {obstacle[2]} {obstacle[3]}')
    print('0 0')
```

This function generates test cases for the "Secret Operation" problem. It creates random values for each parameter defined in the problem statement, ensuring they adhere to the constraints given:

- `Time` ranges from 0 to 100.
- `R` ranges from 1 to 29999.
- Mary's and George's paths consist of random movements with valid constraints.
- Obstacles are randomly generated with valid coordinates.
- The function produces multiple datasets and randomly decides when to stop generating more.

The generated data is printed in the specified input format. Each dataset is followed by the "0 0" line to signify the end of the datasets.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    
    while True:
        # Read the first line
        first_line = fh.readline().strip()
        if first_line == "0 0":
            break
        
        Time, R = map(int, first_line.split())
        
        # Read Mary's moves
        L = int(fh.readline().strip())
        Mary_moves = []
        for _ in range(L):
            MaryX, MaryY, MaryT = map(int, fh.readline().strip().split())
            Mary_moves.append((MaryX, MaryY, MaryT))
        
        # Read George's moves
        M = int(fh.readline().strip())
        George_moves = []
        for _ in range(M):
            GeorgeX, GeorgeY, GeorgeT = map(int, fh.readline().strip().split())
            George_moves.append((GeorgeX, GeorgeY, GeorgeT))
        
        # Read obstacles
        N = int(fh.readline().strip())
        obstacles = []
        for _ in range(N):
            BlockSX, BlockSY, BlockTX, BlockTY = map(int, fh.readline().strip().split())
            obstacles.append((BlockSX, BlockSY, BlockTX, BlockTY))
        
        datasets.append((Time, R, Mary_moves, George_moves, obstacles))
    
    return datasets