Problem p02677 - Generation 1

Orig Description

Score: 300 points
Problem Statement
Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.
An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.
At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?
Constraints
All values in input are integers.
1 \leq A, B \leq 1000
0 \leq H \leq 11
0 \leq M \leq 59
Input
Input is given from Standard Input in the following format:
A B H M
Output
Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}.
Sample Input 13 4 9 0
Sample Output 15.00000000000000000000
The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.
Sample Input 23 4 10 40
Sample Output 24.56425719433005567605
The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

Extracted Specification

Canonicalized Input Description:

An integer A (1 ≤ A ≤ 1000).
An integer B (1 ≤ B ≤ 1000).
An integer H (0 ≤ H ≤ 11).
An integer M (0 ≤ M ≤ 59).

### Example Input:

```
13 4 9 0
```

### Function Signature:
Write a function f(A, B, H, M) that takes in the input.
def f(A: int, B: int, H: int, M: int):
    '''
    A: an integer
    B: an integer
    H: an integer
    M: an integer
    '''

Test Case Generator

Sure! Below is a test case generator for the provided problem statement:

```python
import random
import math

def generate_test_case():
    # Constants
    MAX_HAND_LENGTH = 1000
    MAX_HOURS = 11
    MAX_MINUTES = 59
    
    # Generate random values for A, B, H, and M within their respective constraints
    A = random.randint(1, MAX_HAND_LENGTH)
    B = random.randint(1, MAX_HAND_LENGTH)
    H = random.randint(0, MAX_HOURS)
    M = random.randint(0, MAX_MINUTES)
    
    return A, B, H, M

def calculate_distance(A, B, H, M):
    # Calculate angles in degrees
    hour_angle = (H % 12) * 30 + M * 0.5
    minute_angle = M * 6
    
    # Convert angles to radians
    hour_angle_rad = math.radians(hour_angle)
    minute_angle_rad = math.radians(minute_angle)
    
    # Calculate coordinates of the endpoints
    hour_x = A * math.cos(hour_angle_rad)
    hour_y = A * math.sin(hour_angle_rad)
    minute_x = B * math.cos(minute_angle_rad)
    minute_y = B * math.sin(minute_angle_rad)
    
    # Calculate distance between the two endpoints
    distance = math.sqrt((hour_x - minute_x)**2 + (hour_y - minute_y)**2)
    
    return distance

def main():
    # Generate test case
    A, B, H, M = generate_test_case()
    
    # Calculate the distance
    distance = calculate_distance(A, B, H, M)
    
    # Print input and output in the required format
    print(f"Input: {A} {B} {H} {M}")
    print(f"Output: {distance:.20f}")

# Run the main function to generate a test case and its corresponding output
main()
```

This script generates random values for A, B, H, and M within the specified constraints, calculates the distance between the endpoint of the hour and minute hands, and prints both the input and the output. The calculation ensures that the distance is accurate up to the required precision of \(10^{-9}\).

Extract Arguments

def extract_arguments(fh):
    A, B, H, M = map(int, fh.readline().strip().split())
    return A, B, H, M