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 the number of points.
Two integers \( vw \) and \( vc \) (1 ≤ \( vw, vc \) ≤ 10), representing two speeds.
A list of \( n \) tuples \((xi, yi)\), where each \( xi \) and \( yi \) is an integer between -10,000 and 10,000, and \( xi < xj \) for all \( i < j \).
### Example Input:
```
3
2 1
0 0
50 50
100 0
```
### Function Signature:
Write a function `f(dataset)` that takes in the input.
```python
def f(dataset: List[Tuple[int, int, List[Tuple[int, int]]]]):
'''
dataset: a list of tuples containing:
n: an integer
vw: an integer
vc: an integer
coordinates: a list of n tuples, each containing two integers
'''
```
Test Case Generator
Sure, I can help you with that. Here's a test case generator for the problem "Dig or Climb":
```python
import random
def tcgen():
# Generate a random number of points n, ensuring n is between 1 and 1000
n = random.randint(1, 1000)
# Generate random walking speed vw and cave speed vc between 1 and 10
vw = random.randint(1, 10)
vc = random.randint(1, 10)
# Generate random coordinates for the points, ensuring xi < xj for all i < j
points = []
x_prev = random.randint(-10000, 10000)
y_prev = random.randint(-10000, 10000)
points.append((x_prev, y_prev))
for _ in range(n - 1):
x_next = x_prev + random.randint(1, 200) # Ensuring x_next > x_prev
y_next = random.randint(-10000, 10000)
points.append((x_next, y_next))
x_prev, y_prev = x_next, y_next
# Format the input as specified
input_data = f"{n}\n{vw} {vc}\n" + "\n".join(f"{x} {y}" for x, y in points)
return input_data
# Example usage
if __name__ == "__main__":
test_case = tcgen()
print(test_case)
```
### Explanation:
1. **Number of Points (`n`)**: The number of points is chosen randomly between 1 and 1000.
2. **Speeds (`vw` and `vc`)**: Both walking speed and cave speed are chosen randomly between 1 and 10.
3. **Points (`xi`, `yi`)**:
- The `xi` values are generated such that each successive `xi` is greater than the previous one, ensuring the points are sorted by the `xi` coordinate. This is done by starting with a random `xi` and adding a positive random value to it for each subsequent point.
- The `yi` values are random within the range -10000 to 10000.
4. **Formatting**: The generated points are formatted into the required input format.
### Note:
The termination condition (`n = 0`) is not included in the test case generator, as it is intended to generate a single valid test dataset.
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 = [tuple(map(int, fh.readline().strip().split())) for _ in range(n)]
datasets.append((n, vw, vc, points))
return datasets