Orig Description
Problem C: Dig or Climb
Benjamin Forest VIII is a king of a country. One of his best friends Nod lives in a village far from
his castle. Nod gets seriously sick and is on the verge of death. Benjamin orders his subordinate
Red to bring good medicine for him as soon as possible. However, there is no road from the
castle to the village. Therefore, Red needs to climb over mountains and across canyons to reach
the village. He has decided to get to the village on the shortest path on a map, that is, he will
move on the straight line between the castle and the village. Then his way can be considered as
polyline with n points (x1, y1) . . . (xn , yn ) as illustlated in the following figure.
Figure 1: An example route from the castle to the village
Here, xi indicates the distance between the castle and the point i, as the crow flies, and yi
indicates the height of the point i. The castle is located on the point (x1 , y1 ), and the village is
located on the point (xn , yn).
Red can walk in speed vw . Also, since he has a skill to cut a tunnel through a mountain
horizontally, he can move inside the mountain in speed vc.
Your job is to write a program to the minimum time to get to the village.
Input
The input is a sequence of datasets. Each dataset is given in the following format:
n
vw vc
x1 y1
...
xn yn
You may assume all the following: n ≤ 1,000, 1 ≤ vw, vc ≤ 10, -10,000 ≤ xi, yi ≤ 10,000, and
xi < xj for all i < j.
The input is terminated in case of n = 0. This is not part of any datasets and thus should not
be processed.
Output
For each dataset, you should print the minimum time required to get to the village in a line.
Each minimum time should be given as a decimal with an arbitrary number of fractional digits
and with an absolute error of at most 10-6 . No extra space or character is allowed.
Sample Input
3
2 1
0 0
50 50
100 0
3
1 1
0 0
50 50
100 0
3
1 2
0 0
50 50
100 0
3
2 1
0 0
100 100
150 50
6
1 2
0 0
50 50
100 0
150 0
200 50
250 0
0
Output for the Sample Input
70.710678
100.000000
50.000000
106.066017
150.000000
Extracted Specification
An integer n (1 ≤ n ≤ 1,000), representing some quantity or size, followed by two integers vw and vc (1 ≤ vw, vc ≤ 10).
Then, n pairs of integers xi and yi (-10,000 ≤ xi, yi ≤ 10,000), where xi < xj for all i < j.
The input is terminated by a line containing a single integer 0 which should not be processed.
### Example Input:
```
3
2 1
0 0
50 50
100 0
0
```
### Function Signature:
Write a function f(inputs: List[Tuple[int, int, int, List[Tuple[int, int]]]]) that takes in the input as a list of tuples.
def f(inputs: List[Tuple[int, int, int, List[Tuple[int, int]]]]):
'''
inputs: a list of tuples where each tuple contains:
- an integer n
- two integers vw and vc
- a list of n pairs of integers (xi, yi)
'''
Test Case Generator
Certainly! Below is a test case generator for the "Dig or Climb" problem statement. This generator will produce random valid inputs adhering to the constraints specified in the problem description.
```python
import random
def generate_test_case():
# Constraints
max_n = 1000
max_val = 10000
# Generate a random number of points n (1 <= n <= 1000)
n = random.randint(1, max_n)
# Generate random walking speed vw (1 <= vw <= 10)
vw = random.randint(1, 10)
# Generate random tunneling speed vc (1 <= vc <= 10)
vc = random.randint(1, 10)
# Generate n random points
points = []
x = 0
for _ in range(n):
x += random.randint(1, max_val // n) # Ensure x is strictly increasing
y = random.randint(-max_val, max_val)
points.append((x, y))
return n, vw, vc, points
def generate_test_cases(num_cases):
test_cases = []
for _ in range(num_cases):
test_cases.append(generate_test_case())
return test_cases
def format_test_case(test_case):
n, vw, vc, points = test_case
formatted = f"{n}\n{vw} {vc}\n"
for x, y in points:
formatted += f"{x} {y}\n"
return formatted
def generate_input_file(num_cases, filename):
test_cases = generate_test_cases(num_cases)
with open(filename, 'w') as f:
for test_case in test_cases:
f.write(format_test_case(test_case))
f.write("0\n") # Add the terminating case
# Example usage
if __name__ == "__main__":
num_cases = 5 # Number of test cases you want to generate
generate_input_file(num_cases, "test_cases.txt")
```
Explanation:
1. **Generate Test Case**:
- `generate_test_case` function creates a single random test case.
- `n` (number of points) is randomly chosen between 1 and 1000.
- `vw` (walking speed) and `vc` (tunneling speed) are chosen between 1 and 10.
- `points` is a list of tuples representing `(xi, yi)`. The x-coordinates are strictly increasing, and the y-coordinates are chosen randomly within the range `-10000` to `10000`.
2. **Generate Test Cases**:
- `generate_test_cases` function creates a list of multiple test cases.
3. **Format Test Case**:
- `format_test_case` function converts a test case into the required string format.
4. **Generate Input File**:
- `generate_input_file` function writes the test cases to a file, ending with a "0" to signal termination.
This generator ensures that all constraints are met and that the test cases are formatted correctly for the problem.
Extract Arguments
def extract_arguments(fh):
datasets = []
while True:
n = int(fh.readline().strip())
if n == 0:
break
vw, vc = map(int, fh.readline().strip().split())
points = []
for _ in range(n):
x, y = map(int, fh.readline().strip().split())
points.append((x, y))
datasets.append((n, vw, vc, points))
return datasets