Orig Description
Problem E: Frisbee Dogs
Crane is trying to enter her beloved dog, Jack, into a Frisbee Dog competition. However, she is not confident that Jack will perform well. She would like you to create a program that simulates the competition and estimates Jack's performance.
The competition is held by N dogs on a two-dimensional plane. At the start of the competition, the i-th dog is at position (Dix, Diy). The i-th dog can run at a speed of Vi [m/s], and all dogs are small enough to be considered as points. At any time, two or more dogs can be in the same position.
The competition starts with the launch of the first Frisbee, and from that moment on, the dogs are allowed to move. The Frisbee can also be considered as a point, and the i-th Frisbee is launched from the position (FPix, FPin) with a velocity vector of (FVix, FViy) [m/s], and continues to move at constant speed in a straight line. When the position of a dog and the position of a Frisbee are the same, the dog can acquire the Frisbee.
When the first Frisbee is acquired by a dog, the second Frisbee is launched. When the second Frisbee is acquired, the third is launched, and so on, with the next Frisbee launched immediately after it is acquired. The competition ends when M Frisbees are acquired.
Needless to say, the goal of the dogs is to acquire as many Frisbees as possible. The dogs take the following strategy:
When a Frisbee is launched, a dog moves to be able to acquire it as soon as possible, and acquires the Frisbee. However, if the dog cannot acquire the Frisbee, it waits at its current location.
Whether a dog can acquire a Frisbee is determined independently of the actions of other dogs. That is, even if a dog moves to acquire a Frisbee, it may be acquired by another dog first. When a Frisbee is acquired by any dog and a new Frisbee is launched, the dogs take the above strategy for the new Frisbee.
Your program should output the number of Frisbees acquired by each dog.
Input
The input file consists of multiple datasets.
The first line of each dataset gives the number of dogs N (1 ≤ N ≤ 10) and the number of Frisbees M (1 ≤ M ≤ 1000).
The following N lines give the initial position and speed of the dogs, Dix, Diy, and Vi, separated by a single space.
The following M lines give the launch position and velocity of the Frisbees, FPix, FPin, FVix, and FViy, separated by a single space.
The given coordinate values are real numbers, and their absolute value does not exceed 1000. The given speed is a real number, and 1 ≤ Vi ≤ 100, -25 ≤ FVix, FViy ≤ 25. It can be assumed that there is no Frisbee that cannot be acquired by any dog.
If a Frisbee is acquired by a dog at time t, no dog can acquire it before t+1e-6.
During the simulation, the absolute values of the x and y coordinates of the dogs do not exceed 1e+8.
The end of the input is indicated by N=0 and M=0.
Output
Output the number of Frisbees acquired by each dog on a single line, separated by a space. The order of the output must be the same as the order of the input.
Sample Input
2 1
12 5 3
0 17 3
0 0 2 2
2 3
2 0 2
100 100 2
0 0 -1 0
-2 -5 0 3
100 100 1 1
0 0
Output for the Sample Input
1 0
2 1
Extracted Specification
An integer N (1 ≤ N ≤ 10), representing some quantity.
An integer M (1 ≤ M ≤ 1000), representing some quantity.
N lines follow, each containing three real numbers X, Y, and V, where -1000 ≤ X, Y ≤ 1000 and 1 ≤ V ≤ 100.
M lines follow, each containing four real numbers X, Y, VX, and VY, where -1000 ≤ X, Y ≤ 1000 and -25 ≤ VX, VY ≤ 25.
The end of the input is indicated by N=0 and M=0.
### Example Input:
```
2 1
12 5 3
0 17 3
0 0 2 2
2 3
2 0 2
100 100 2
0 0 -1 0
-2 -5 0 3
100 100 1 1
0 0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
```python
def f(inputs: List[Tuple[int, int, List[Tuple[float, float, float]], List[Tuple[float, float, float, float]]]]):
'''
inputs: a list of tuples, each containing:
An integer
An integer
A list of tuples, each containing three real numbers
A list of tuples, each containing four real numbers
'''
```
Test Case Generator
Sure, let's write a test case generator for the problem "Frisbee Dogs". The generator will create random values for the number of dogs \(N\), the number of Frisbees \(M\), the initial positions and speeds of the dogs, and the launch positions and velocities of the Frisbees.
Here is the test case generator in Python:
```python
import random
def generate_random_float(min_value, max_value, precision=6):
"""Generates a random float between min_value and max_value with the specified precision."""
return round(random.uniform(min_value, max_value), precision)
def tcgen():
# Generate random number of dogs (N) and Frisbees (M)
N = random.randint(1, 10)
M = random.randint(1, 1000)
# Generate initial positions and speeds for N dogs
dogs = []
for _ in range(N):
Dix = generate_random_float(-1000, 1000)
Diy = generate_random_float(-1000, 1000)
Vi = generate_random_float(1, 100)
dogs.append((Dix, Diy, Vi))
# Generate launch positions and velocities for M frisbees
frisbees = []
for _ in range(M):
FPix = generate_random_float(-1000, 1000)
FPin = generate_random_float(-1000, 1000)
FVix = generate_random_float(-25, 25)
FViy = generate_random_float(-25, 25)
frisbees.append((FPix, FPin, FVix, FViy))
return N, M, dogs, frisbees
def format_test_case(N, M, dogs, frisbees):
"""Formats the test case into the required input format."""
result = []
result.append(f"{N} {M}")
for dog in dogs:
result.append(f"{dog[0]} {dog[1]} {dog[2]}")
for frisbee in frisbees:
result.append(f"{frisbee[0]} {frisbee[1]} {frisbee[2]} {frisbee[3]}")
return "\n".join(result)
# Generate a test case
N, M, dogs, frisbees = tcgen()
formatted_test_case = format_test_case(N, M, dogs, frisbees)
print(formatted_test_case)
# Generate multiple test cases, including the termination case
test_cases = []
for _ in range(5): # Adjust the number of test cases as needed
N, M, dogs, frisbees = tcgen()
test_cases.append(format_test_case(N, M, dogs, frisbees))
test_cases.append("0 0") # Add the termination case
# Print all test cases
for test_case in test_cases:
print(test_case)
print() # Add a blank line between test cases
```
Here is a breakdown of what each part of the code does:
1. **`generate_random_float` function**: Generates a random float between a specified minimum and maximum value with a given precision.
2. **`tcgen` function**: Generates a random test case with:
- A random number of dogs \(N\) (1 ≤ \(N\) ≤ 10).
- A random number of Frisbees \(M\) (1 ≤ \(M\) ≤ 1000).
- Random initial positions and speeds for each dog.
- Random launch positions and velocities for each Frisbee.
3. **`format_test_case` function**: Formats the generated test case into the required input format for the problem.
4. **Main script**: Generates and prints multiple test cases, including the termination case (`0 0`).
This generator will help create diverse test cases to test the robustness of your Frisbee Dogs competition simulation program.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
# Read the first line of the dataset
line = fh.readline().strip()
if line == '0 0':
break
N, M = map(int, line.split())
dogs = []
for _ in range(N):
Dix, Diy, Vi = map(float, fh.readline().strip().split())
dogs.append((Dix, Diy, Vi))
frisbees = []
for _ in range(M):
FPix, FPin, FVix, FViy = map(float, fh.readline().strip().split())
frisbees.append((FPix, FPin, FVix, FViy))
datasets.append((N, M, dogs, frisbees))
return datasets