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), representing some quantity or duration.
An integer R (0 < R < 30000), representing some other quantity.
An integer L (2 ≤ L ≤ 20), representing the number of data points in the first list of tuples.
L tuples, each containing three integers (Xi, Yi, Ti), where each integer is between -10000 and 10000, representing some information.
An integer M (2 ≤ M ≤ 20), representing the number of data points in the second list of tuples.
M tuples, each containing three integers (Xj, Yj, Tj), where each integer is between -10000 and 10000, representing some other information.
An integer N (0 ≤ N ≤ 20), representing the number of data points in the third list of tuples.
N tuples, each containing four integers (SXk, SYk, TXk, TYk), where each integer is between -10000 and 10000, representing some other information.
### Example Input:
```
50 100
2
50 50 0
51 51 50
2
0 0 0
1 1 50
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 containing integers and nested lists of tuples with integers
'''
```
Test Case Generator
Sure! I'll write a test case generator for the problem statement "Secret Operation". This generator will create random valid test cases following the given constraints.
Here is the Python code for the test case generator:
```python
import random
def generate_move_sequence(max_time, max_coord, max_segments):
segments = random.randint(2, max_segments)
times = sorted(random.sample(range(1, max_time), segments - 1))
times = [0] + times + [max_time]
move_sequence = []
for i in range(segments):
x = random.randint(-max_coord, max_coord)
y = random.randint(-max_coord, max_coord)
t = times[i]
move_sequence.append((x, y, t))
return move_sequence
def generate_obstacles(max_coord, max_obstacles):
obstacles = random.randint(0, max_obstacles)
obstacle_list = []
for _ in range(obstacles):
sx = random.randint(-max_coord, max_coord)
sy = random.randint(-max_coord, max_coord)
tx = random.randint(sx, sx + random.randint(1, 10)) # Ensure non-zero area
ty = random.randint(sy, sy + random.randint(1, 10))
obstacle_list.append((sx, sy, tx, ty))
return obstacle_list
def tcgen():
max_time = 100
max_coord = 10000
max_segments = 20
max_obstacles = 20
max_vision = 29999
Time = random.randint(1, max_time)
R = random.randint(1, max_vision)
L = random.randint(2, max_segments)
mary_moves = generate_move_sequence(Time, max_coord, L)
M = random.randint(2, max_segments)
george_moves = generate_move_sequence(Time, max_coord, M)
N = random.randint(0, max_obstacles)
obstacles = generate_obstacles(max_coord, N)
return Time, R, mary_moves, george_moves, obstacles
def print_test_case(Time, R, mary_moves, george_moves, obstacles):
print(f"{Time} {R}")
print(len(mary_moves))
for x, y, t in mary_moves:
print(f"{x} {y} {t}")
print(len(george_moves))
for x, y, t in george_moves:
print(f"{x} {y} {t}")
print(len(obstacles))
for sx, sy, tx, ty in obstacles:
print(f"{sx} {sy} {tx} {ty}")
print("0 0")
if __name__ == "__main__":
random.seed(42) # For reproducibility
for _ in range(5): # Generate 5 test cases
Time, R, mary_moves, george_moves, obstacles = tcgen()
print_test_case(Time, R, mary_moves, george_moves, obstacles)
print()
```
### Explanation:
- **generate_move_sequence**: Generates a random move sequence for Mary or George with valid constraints.
- **generate_obstacles**: Generates random obstacles with valid coordinates.
- **tcgen**: Generates a complete test case with Mary’s moves, George’s moves, and obstacles.
- **print_test_case**: Prints a generated test case in the required format.
This generator creates random test cases within the constraints specified in the problem statement. You can run this script and it will produce multiple test cases for you.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
first_line = fh.readline().strip()
if first_line == "0 0":
break
Time, R = map(int, first_line.split())
L = int(fh.readline().strip())
mary_moves = []
for _ in range(L):
mary_moves.append(tuple(map(int, fh.readline().strip().split())))
M = int(fh.readline().strip())
george_moves = []
for _ in range(M):
george_moves.append(tuple(map(int, fh.readline().strip().split())))
N = int(fh.readline().strip())
obstacles = []
for _ in range(N):
obstacles.append(tuple(map(int, fh.readline().strip().split())))
datasets.append((Time, R, mary_moves, george_moves, obstacles))
return datasets