Orig Description
Problem G: The Humans Braving the Invaders
Problem
Currently, Earth is under attack by invaders from space, and only we who are in the base, which is the only surviving humans, are left. There is little military power left to fight against them. Nevertheless, we do not give up here. Completely annihilating the Invader is the last means for humanity to survive. We must fight to the end as representatives of the remaining humanity. The following describes the content of the final operation that will take place now.
First, since our military power is far too low compared to that of the Invaders, we will take refuge in this base and conduct a siege battle. This base is surrounded by high mountains, and the only way for the Invaders to invade is to pass through the straight road in front of the base. Let's call this road a field. Due to this feature, it is possible to attack the Invaders concentratedly in front. We who are in the base attack the Invaders with two types of weapons. One is a sniper rifle that aims at one Invader. The other is a grenade launcher that can attack a wide range.
Your job as the only programmer among us humans is to simulate the battle based on the action records of the Invaders and us. The action record is given in query format. Each query consists of one or more integers and is given as follows:
0
The Invader appears at a position L distance from the base on the field.
1 d
All Invaders currently on the field move d closer to the base. After this action, Invaders that reach the base will receive damage, and those enemies will disappear from the field. If damage is received, output "damage (number of Invaders that reached the base)" on one line.
2 k
If the number of Invaders currently on the field is equal to or greater than k , attack the k th Invader from the base with a sniper rifle. The Invader will disappear from the field. Then output "hit" on one line. If the number of Invaders on the field is less than k , output "miss" on one line.
3 x r
Attack a range of r with a grenade launcher at a position x distance from the base. All Invaders on the field whose distance from the base is within r from the point of impact at a distance of x from the base will disappear from the field. Then output "bomb (number of Invaders defeated)" on one line. As a supplement, the base will not receive any damage from the grenade launcher.
4 k
If the number of Invaders on the field is equal to or greater than k , output "distance (distance between the k th Invader closest to the base and the base)" on one line. If the number of Invaders on the field is less than k , output "distance -1" on one line.
That's all for the explanation of the operation. All hands, start the operation! ...Good luck.
Input
The input consists of multiple data sets. Each data set is represented as follows. The first line gives two integers Q and L separated by a space. The following Q lines give the queries described above. The input ends with two zeros.
Constraints
The input satisfies the following conditions.
All values in the input are integers.
1 ≤ Q ≤ 100000
1 ≤ L ≤ 109
1 ≤ d , k ≤ 109
0 ≤ x ≤ L
0 ≤ r ≤ 109
There are no more than two Invaders at the same position.
There are no more than three data sets.
Output
For each data set, output according to the instruction of the query to be output. Output "end" at the end of each data set.
Sample Input
18 10
0
4 1
1 1
4 1
0
1 1
0
2 2
1 10
0
1 1
0
1 5
3 4 0
3 4 1
0
9 10
4 1
2 2
3 5 5
0
4 1
2 2
3 5 5
0
2 1
0 0
Sample Output
distance 10
distance 9
hit
damage 2
bomb 1
bomb 2
end
distance -1
miss
bomb 0
distance 10
miss
bomb 1
hit
end
Extracted Specification
An integer Q (1 ≤ Q ≤ 100000) and an integer L (1 ≤ L ≤ 10^9).
Followed by Q lines of queries, each containing:
- Query type 0: no additional integers.
- Query type 1: an integer d (1 ≤ d ≤ 10^9).
- Query type 2: an integer k (1 ≤ k ≤ 10^9).
- Query type 3: two integers x (0 ≤ x ≤ L) and r (0 ≤ r ≤ 10^9).
- Query type 4: an integer k (1 ≤ k ≤ 10^9).
The input ends with two zeros.
### Example Input:
```
18 10
0
4 1
1 1
4 1
0
1 1
0
2 2
1 10
0
1 1
0
1 5
3 4 0
3 4 1
0
9 10
4 1
2 2
3 5 5
0
4 1
2 2
3 5 5
0
2 1
0 0
```
### Function Signature:
Write a function f(inputs) that takes in the input.
def f(inputs: List[Tuple[int, int, List[Tuple[int, ...]]]]):
'''
inputs: a list of tuples, each containing an integer Q, an integer L, and a list of tuples representing queries.
'''
Test Case Generator
Sure, here's a test case generator for the given problem statement, "The Humans Braving the Invaders":
```python
import random
def generate_query(L):
query_type = random.randint(0, 4)
if query_type == 0:
return "0"
elif query_type == 1:
d = random.randint(1, 10**9)
return f"1 {d}"
elif query_type == 2:
k = random.randint(1, 10**9)
return f"2 {k}"
elif query_type == 3:
x = random.randint(0, L)
r = random.randint(0, 10**9)
return f"3 {x} {r}"
elif query_type == 4:
k = random.randint(1, 10**9)
return f"4 {k}"
def tcgen():
datasets = []
num_datasets = random.randint(1, 3)
for _ in range(num_datasets):
Q = random.randint(1, 100000)
L = random.randint(1, 10**9)
queries = [generate_query(L) for _ in range(Q)]
datasets.append((Q, L, queries))
return datasets
def print_test_case(datasets):
for Q, L, queries in datasets:
print(Q, L)
for query in queries:
print(query)
print("0 0")
if __name__ == "__main__":
random.seed(42) # For reproducibility
datasets = tcgen()
print_test_case(datasets)
```
### Explanation
1. **generate_query(L)**: This function generates a single random query. It selects a query type (0 through 4) and generates appropriate random values for each type.
- `0`: Invader appears.
- `1 d`: All invaders move `d` closer to the base.
- `2 k`: Sniper rifle attack on the k-th invader.
- `3 x r`: Grenade launch attack at distance `x` with radius `r`.
- `4 k`: Distance query for the k-th closest invader.
2. **tcgen()**: This function generates multiple datasets (between 1 and 3). For each dataset:
- It randomly determines `Q` (number of queries) and `L` (distance from the base).
- Then, it generates `Q` random queries using the `generate_query(L)` function.
3. **print_test_case(datasets)**: This function prints the generated datasets in the required format.
4. **Main Execution**: The main block sets a random seed for reproducibility, generates the test cases, and prints them.
This generator will create random but valid test cases that you can use to test your solution for the problem "The Humans Braving the Invaders".
Extract Arguments
def extract_arguments(fh):
data_sets = []
while True:
q, l = map(int, fh.readline().strip().split())
if q == 0 and l == 0:
break
queries = []
for _ in range(q):
queries.append(list(map(int, fh.readline().strip().split())))
data_sets.append((q, l, queries))
return data_sets
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# data_sets = extract_arguments(fh)
# for data_set in data_sets:
# print(data_set)