Problem:
 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 1 3 4 9 0      Sample Output 1 5.00000000000000000000  The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.        Sample Input 2 3 4 10 40      Sample Output 2 4.56425719433005567605  The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

Solution (Python):
import math

A, B, H, M = map(int, input().split())

theta = math.radians(30 * H - 5.5 * M)

ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))

print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
T=H*60+M
theta=2*math.pi*11*T/(12*60)
X=A-B*math.cos(theta)
Y=-B*math.sin(theta)
print(math.sqrt(X**2+Y**2))

Solution (Python):
from math import sin, cos, radians

A, B, H, M = map(int, input().split())

at_d = (3-(H+M/60))%12 * 30
bt_d = (15-M)%60 * 6



at_r = radians(at_d)
bt_r = radians(bt_d)

ax, ay = (cos(at_r)*A, sin(at_r)*A)
bx, by = (cos(bt_r)*B, sin(bt_r)*B)

r = ((ax-bx)**2 + (ay-by)**2)**(1/2)
print(r)

Solution (Python):
import math
from sys import stdin
input = stdin.readline


def main():
  A, B, H, M = list(map(int, input().split()))

  theta_a = 2*math.pi * ((H * 60 + M) / (12*60))
  theta_b = 2*math.pi * (M / 60)

  print( math.sqrt( (A*math.cos(theta_a) - B*math.cos(theta_b))**2 + \
                    (A*math.sin(theta_a) - B*math.sin(theta_b))**2 ) )

if(__name__ == '__main__'):
  main()

Solution (Python):
import math
A,B,H,M=map(int,input().split())
M_rad = math.radians(M*6)
H_rad = math.radians(H*30+M*0.5)
rad = M_rad - H_rad
ans = math.sqrt(A**2+B**2-2*A*B*math.cos(rad))
print(ans)

Solution (Python):
import math

def resolve():
    A, B, H, M = map(int, input().split())

    h_rad = math.radians(30*H + M / 2)
    h_y = A * math.cos(h_rad)
    h_x = A * math.sin(h_rad)
    m_rad = math.radians(6*M)
    m_y = B * math.cos(m_rad)
    m_x = B * math.sin(m_rad)

    ans = math.sqrt((h_y - m_y)**2 + (h_x - m_x)**2)
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
import math

a, b, h, m = map(int, input().split())

tha = (math.pi / 6)*h+(math.pi / 360)*m
thb = (math.pi / 30)*m
th = abs(tha-thb)

costh = math.cos(th)

c = (a**2 + b**2 - 2*a*b*costh)**(0.5)

print(c)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(abs(30 * H - 5.5 * M))))
print(ans)

Solution (Python):
import math
a, b, h, m = map(int, input().split())

angle_a = h*360/12 + m*360/60/12
angle_b = m*360/60
ax = a * math.sin(math.radians(angle_a))
ay = a * math.cos(math.radians(angle_a))
bx = b * math.sin(math.radians(angle_b))
by = b * math.cos(math.radians(angle_b))
print(math.sqrt(abs(ax-bx)**2 + abs(ay-by)**2))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
deg_a=6*m
deg_b=30*h+m/2
deg_c=abs((deg_a)-(deg_b))
rad=math.radians(deg_c)
c=a**2+b**2-2*a*b*math.cos(rad)
print(c**0.5)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
from cmath import pi, rect
sys.setrecursionlimit(10**7)

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

A,B,H,M = LI()

H += M / 60
H = H/12 * 2*pi
M = M/60 * 2*pi


l = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(H-M) )
 

zA = A * np.exp(H*1j)
zB = B * np.exp(M*1j)

l=abs(zA - zB)

print(l)

Solution (Python):
import math
a,b,h,m = list(map(int, input().split())) 

short_deg = (((h*60*60+m*60) / (12*60*60)  * 360)+90) % 360
long_deg = (((h*60*60+m*60) / (60*60)  * 360)+90) % 360

short_x = math.cos(short_deg * (math.pi / 180) )*a
short_y = math.sin(short_deg * (math.pi / 180) )*a

long_x = math.cos(long_deg * (math.pi / 180) )*b
long_y = math.sin(long_deg * (math.pi / 180) )*b

l = ((short_x-long_x)**2 + (short_y-long_y)**2 )**0.5
print(l)

Solution (Python):
from math import sin, cos, pi

a, b, h, m = map(int, input().split())

time = h * 60 + m
half = 12 * 60
x_a = a * cos(2 * pi * time / half)
y_a = a * sin(2 * pi * time / half)
x_b = b * cos(2 * pi * m / 60)
y_b = b * sin(2 * pi * m / 60)
l = ((x_a - x_b) ** 2 + (y_a - y_b) ** 2) ** 0.5
print(l)

Solution (Python):
A,B,H,M=map(int, input().split())
import math

angle = abs(30*H-5.5*M)
angle = min(angle, 360-angle)*math.pi/180
 
c=A**2 + B**2 -2*A*B* math.cos(angle)
c=c**0.5
 
print(c)

Solution (Python):
a, b, h, m = map(int, input().split())
from math import cos,sin, sqrt, radians

x_a = - a * cos(radians(360/12.0*h+360/12/60*m))
y_a = a * sin(radians(360/12.0*h+360/12/60*m))
x_b = - b * cos(radians(360/60.0*m))
y_b = b * sin(radians(360/60.0*m))

print(sqrt((x_a-x_b)**2+(y_a-y_b)**2))

Solution (Python):
"""AtCoder."""

import math

a, b, h, m = [int(v) for v in input().split(' ')]


class Point:

    def __init__(self, r, v):
        self.r = r
        self.w = (2 * math.pi) / v

    def get_pos(self, t):
        wt = self.w * t
        return self.r * math.cos(wt), self.r * math.sin(wt)


p1 = Point(a, 12 * 60)
p2 = Point(b, 60)

minute = (h * 60) + m
x1, y1 = p1.get_pos(minute)
x2, y2 = p2.get_pos(minute)

print(math.sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)))

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))
angle_h = 2 * math.pi * ((60 * h + m) / 720)
angle_m = 2 * math.pi * (m / 60)

diff = angle_m - angle_h
d = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(diff))
print(d)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
angle = math.radians((60*H+M)/2-6*M)
L2 = A**2 + B**2 - 2*A*B*math.cos(angle)
print(L2**0.5)

Solution (Python):
import math

A,B,H,M = list(map(int, input().split()))
if H == 0:
    H_angle = (360/720)*M
    M_angle = 6*M
else:
    H_M = H*60
    H_angle = (360/720)*(H_M + M)
    M_angle = 6*M

dif = H_angle-M_angle
cos = math.cos(math.radians(H_angle-M_angle))
ans = A**2 + B**2 -2*A*B*cos
print(math.sqrt(ans))

Solution (Python):
"""
○ 角速度 = θ / t [rad/s]
・時針
ω = θ / t
  = math.radians(360) / (12 * 60 * 60) [rad/s]
・分針
ω = θ / t
  = math.radians(360) / (60 * 60) [rad/s]
"""

import math

def colon():
    
    A, B, H, M = map(int, input().split())
    
    angular_velocity_h = math.radians(360) / (12 * 60 * 60)
    angular_velocity_m = math.radians(360) / (60 * 60)
    
    radian_h = angular_velocity_h * ((H * 60 * 60) + (M * 60))
    
    radian_m = angular_velocity_m * (M * 60)
    
    radian_hm = abs(radian_h - radian_m)
    if radian_hm > math.pi:
        radian_hm = 2 * math.pi - radian_hm
    elif radian_hm == math.pi:
        return A + B
    elif math.pi > radian_hm:
        pass
    
    distance = math.sqrt((A**2 + B**2) - (2 * A * B * math.cos(radian_hm)))
    
    return distance

result = colon()
print(result)

Solution (Python):













































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    
    A, B, H, M = list(map(int, lines[0].split()))
    
    
    
    
    
    
    
    

    h = 360 / 12 * (H+(M/60))
    m = 360 / 60 * M
    a = abs(h-m)
    log(f'h=[{h}], m=[{m}], a=[{a}]')

    
    

    
    import math
    x = math.cos(a/180*math.pi) * B
    y = math.sin(a/180*math.pi) * B

    log(f'x=[{x}], y=[{y}]')

    result = ((x-A)**2 + y**2)**0.5

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 4 9 0']
        lines_export = [5.00000000000000000000]
    if pattern == 2:
        lines_input = ['3 4 10 40']
        lines_export = [4.56425719433005567605]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
A, B, H, M = map(int, input().split())

deg = min(abs(H*360/12 + M*360/12/60 - M*360/60), 360 - abs(H*360/12 + M*360/12/60 - M*360/60))
theta = deg * np.pi /180
ans = np.sqrt(np.power(A,2)+np.power(B,2)-2*A*B*np.cos(theta))
 
print(ans)

Solution (Python):
import numpy as np

a,b,h,m=list(map(int,input().split()))

deg = min(abs(h*360/12+m*360/12/60-m*360/60),360-abs(h*360/12+m*360/12/60-m*360/60))
theta = deg * np.pi /180
ans = np.sqrt(np.power(a,2)+np.power(b,2)-2*a*b*np.cos(theta))

print(ans)

Solution (Python):
import math
import numpy as np

A, B, H, M = map(int,input().split())
long = np.array([A*math.sin(H/12*2*math.pi+M/60*math.pi/6), A*math.cos(H/12*2*math.pi+M/60*math.pi/6)])
short = np.array([B*math.sin(M/60*2*math.pi), B*math.cos(M/60*2*math.pi)])

print(np.linalg.norm(long-short))

Solution (Python):


from typing import *
import itertools
import math
import sys

INF = float('inf')


def law_of_cosines(a: float, b: float, gamma: float, is_degree: bool = False) -> float:
    if is_degree:
        gamma = math.radians(gamma)
    return a**2 + b**2 - 2*a*b*math.cos(gamma)


def solve(A: int, B: int, H: int, M: int):
    deg = (H + M/60) * 30 - M * 6
    return math.sqrt(law_of_cosines(A, B, deg, is_degree=True))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    H = int(next(tokens))  
    M = int(next(tokens))  
    print(f'{solve(A, B, H, M):.10f}')


if __name__ == '__main__':
    main()

Solution (Python):
import math
a, b, h, m = map(int, input().split())
alpha = 30.0 * h + (30 * m / 60)
beta = m * 6.0
if alpha < beta:
    theta = beta - alpha
else:
    theta = alpha - beta
print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(theta))))

Solution (Python):
a, b, h, m = map(int, input().split())

t = h + (m / 60)


a_deg = 360 * (t / 12)

b_deg = 360 * (m / 60)


import math
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(abs(a_deg-b_deg))))

print(c)

Solution (Python):

from math import cos, pi

A, B, H, M = map(int, input().split())

theta = abs(M * 6 - (H * 30 + M / 2)) / 360 * 2 * pi
c = (A ** 2 + B ** 2 - 2 * A * B * cos(theta)) ** 0.5
print(c)

Solution (Python):
A, B, H, M = map(int, input().split())

import math

theta = (30 * H) - (5.5 * M)

d2 = A * A + B * B - 2 * A * B * math.cos(math.radians(theta))

d = math.sqrt(d2)

print(d)

Solution (Python):
import cmath

A, B, H, M = map(int, input().split())

h = cmath.rect(A, (H / 6 + M / 360) * cmath.pi)
m = cmath.rect(B, M / 30 * cmath.pi)
print(abs(h - m))

Solution (Python):
import numpy as np

raw = input()
rawl = raw.split()
A = int(rawl[0])
B = int(rawl[1])
H = int(rawl[2])
M = int(rawl[3])
theta = 2*np.pi*(H/12+M/720-M/60)
print((A*A+B*B-2*A*B*np.cos(theta))**(0.5))

Solution (Python):
import numpy as np

raw = input()
rawl = raw.split()
A = int(rawl[0])
B = int(rawl[1])
H = int(rawl[2])
M = int(rawl[3])
theta = 2*np.pi*(H/12+M/720-M/60)
print((A*A+B*B-2*A*B*np.cos(theta))**(0.5))

Solution (Python):
from sys import stdin
import sys, math

a, b, h, m = [int(x) for x in stdin.readline().rstrip().split()]

x = 30*h + 0.5*m
y = 6*m

z = abs(x-y)
if z > 180: z = 360 - z

c = a**2 + b**2 - 2*a*b*math.cos(math.radians(z))
c = math.sqrt(c)

print(c)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
theta = math.pi * abs((h+m/60)/6 - m/30);
val = math.sqrt(a*a + b*b - 2*a*b*math.cos(theta))
print(val)

Solution (Python):

import math

def solve():
    a,b,h,m=map(int,input().split())
    sita=math.pi*2*((h+m/60)/12-m/60)
    c=math.sqrt(a*a+b*b-2*a*b*math.cos(sita))
    return c

print(solve())

Solution (Python):
import math
A, B, H, M = map(int, input().split())

wa = 360/12
wb = 360/1
t = H + M/60
theta = math.radians((wa*t)%360 - (wb*t)%360)
print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(theta)))

Solution (Python):
import math
def get_theta(H,M):
    M_angle = 6 * M
    H_angle = 30 * H + 0.5 * M
    return (M_angle - H_angle) * math.pi / 180 
def calculate_vector_distance(a,b,theta):
    return math.sqrt(a**2 + b ** 2 - 2*a*b*math.cos(theta))
if __name__ == "__main__":
    A,B,H,M = map(int,input().split())
    print(calculate_vector_distance(A,B,get_theta(H,M)))

Solution (Python):
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()


A, B, H, M = inpl()
h = 360 * H / 12 + 30 * M / 60
m = 360 * M / 60
sa = abs(h - m)
sa = min(sa, 360-sa)

print((A*A + B*B - 2*A*B*math.cos(sa*math.pi/180))**0.5)


ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Solution (Python):
a,b,h,m = map(int,input().split())
import math

C = abs(360 / 60 * m - 360 / 12 * h - 360 / 12 / 60 * m)
if C > 180:
    C = 360 - C


cosC = math.cos(math.radians(C))


print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosC))

Solution (Python):

import math

a, b, h, m = map(int, input().split())

hour = 30 * h + 0.5 * m
minutes = 6 * m

theta = max(hour, minutes) - min(hour, minutes)
theta = min(360 - theta, theta)

c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(theta)))
print(c)

Solution (Python):
import math
number=list(map(int,input().split()))
H_l,M_l,H,M=number[0],number[1],number[2],number[3]
H_c=math.cos(math.radians(float(H/12)*360+float(M/60)*30))
H_s=math.sin(math.radians(float(H/12)*360+float(M/60)*30))
M_c=math.cos(math.radians(float(M/60)*360))
M_s=math.sin(math.radians(float(M/60)*360))

H_x,H_y=float(H_l*H_c),float(H_l*H_s)
M_x,M_y=float(M_l*M_c),float(M_l*M_s)
answer=float((H_x-M_x)**2+(H_y-M_y)**2)**float(1/2)
print(answer)

Solution (Python):
from math import cos, pi, sqrt

a, b, h, m = map(float, input().split())
x = 30 * (h + m / 60)
y = 360 * m / 60
z = abs(x - y)
z = min(z, 360 - z)
print(sqrt(a * a + b * b - 2 * a * b * cos(pi * z / 180)))

Solution (Python):
from math import sqrt,cos,pi

a,b,h,m = map(int,input().split())
print(sqrt(a*a+b*b-2*a*b*cos(((60*h+m)/720)*(2*pi)-(m/60)*(2*pi))))

Solution (Python):
A, B, H, M = map(int, input().split())

import math



a_omega_m = math.pi/2/3/60


b_omega_m = 2*math.pi/60


T = H*60 + M


A_y = A*math.sin(a_omega_m*T)
A_x = A*math.cos(a_omega_m*T)
B_y = B*math.sin(b_omega_m*T)
B_x = B*math.cos(b_omega_m*T)

print(math.sqrt((A_y - B_y)**2 + (A_x - B_x)**2))

Solution (Python):
import math
a, b, h, m=map(int, input().split())

h=(h/12)*360 + (m/60)*30
m=(m/60)*360
ans=a**2+b**2-2*a*b*math.cos(math.radians(h-m))
print(math.sqrt(ans))

Solution (Python):
import math
 
a,b,h,m = map(int, input().split())
 
h = (h/12)*360 + (m/60)*30
m = (m/60)*360
ans = a**2 + b**2 -2*a*b*math.cos(math.radians(h-m))
print(math.sqrt(ans))

Solution (Python):
import math

A , B , H , M = map(int,input().split())

Hour_rad = H * 30
Hour_rad += M * 0.5

Min_rad = M * 6




rad = abs(Hour_rad - Min_rad)

if rad > 180:
    rad = 360 - rad





ans = A**2 + B**2 - ( 2 * A * B * math.cos( math.radians ( rad )) )
ans = math.sqrt(ans)

print(ans)

Solution (Python):
import math

a,b,h,m = map(int, input().split())

h = (h/12)*360 + (m/60)*30
m = (m/60)*360
ans = a**2 + b**2 -2*a*b*math.cos(math.radians(h-m))
print(math.sqrt(ans))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
 
h_arg = (h/12)*360 + (m/60)*30
m_arg = (m/60)*360
 
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(h_arg-m_arg)))
print(ans)

Solution (Python):
import numpy as np
A,B,H,M = map(int,input().split())

M_a = (H/6 + M/360) * np.pi
M_b = (M/30) * np.pi

r = max(M_a,M_b) - min(M_a,M_b)

c = np.sqrt(A**2+B**2-(2*A*B*np.cos(r)))

print(c)

Solution (Python):
import math
A, B, H, M = map(int, input().split())

A_angle = (( H+( M/60 ))/12)*2*math.pi
B_angle = (M/60)*2*math.pi

ans_pos_x = A*math.cos(A_angle) - B*math.cos(B_angle)
ans_pos_y = A*math.sin(A_angle) - B*math.sin(B_angle)

ans = math.sqrt( ans_pos_x**2 + ans_pos_y**2 )

print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
partition=0.5
minute=m*6

hour=30*h + 0.5*m
dif=abs(hour-minute)
cos=math.cos(math.pi*(dif/180));
print(math.sqrt(a**2 + b**2 - 2*a*b*cos))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
partition=0.5
minute=m*6

hour=30*h + 0.5*m
dif=abs(hour-minute)
cos=math.cos(math.pi*(dif/180));
print(math.sqrt(a**2 + b**2 - 2*a*b*cos))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
kakudo1 = m*6
kakudo2 = h*30 + m*0.5
kakudo = abs(kakudo1-kakudo2)
kakudo = 360 - kakudo if kakudo > 180 else kakudo

print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))))

Solution (Python):

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, cos
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A, B, H, M = map(int, input().split())
    a = H * 30 + M * 0.5
    b = M * 6

    d = min(abs(a - b), 360 - abs(a - b))
    ans = A * A + B * B + - 2 * A * B * cos(d * pi / 180)
    print(sqrt(ans))


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
import math
a, b, h, m = map(int, input().split())
 
rad_a = h * 30 + m * 0.5
rad_b = m * 6
 
rad = abs(rad_a - rad_b)
if rad > 180:
    rad = 360 - rad
 
cos_theta = math.cos(math.radians(rad))
L = a + b + math.sqrt(a*a + b*b - (2 * a * b * cos_theta))
print(L - a - b)

Solution (Python):
import math

a,b,h,m = map(int,input().split())

th = m / 60 - (m + 60*h) / 720
pi = math.pi
print(math.sqrt(a**2 + b ** 2 - 2 * a * b * math.cos(2*pi*th)))

Solution (Python):
import math
A, B, H, W = map(int, input().split())
R = abs(30*H+.5*W-6*W)
print((A**2+B**2-2*A*B*math.cos(math.radians(R)))**.5)

Solution (Python):
import math
a, b, h, m = map(int, input().split(' '))

rec_h = 30 * h + 0.5 * m
rec_m = 6 * m
rec = abs(rec_h-rec_m)
if rec > 180:
    rec = 360 - rec

x = b * math.sin(math.radians(rec))
y = a - b * math.cos(math.radians(rec))

r = math.sqrt(x**2 + y**2)
print(r)

Solution (Python):
import math
a,b,h,m = map(int,input().split())

time = h * 60 + m


angle1 = time * (1/30 - 1/360)%2

angle2 = min(angle1,2 - angle1)

angle3 = math.pi * angle2


d = math.sqrt(a**2 + b**2 -2*a*b*math.cos(angle3))
print(d)

Solution (Python):
import math
a,b,h,m=map(float,input().split())
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians((h*60+m)*11%720/2))))

Solution (Python):
import math

a,b,h,m = map(int,input().split())

def clock_to_minutes(h, m):
  minutes = m
  minutes += h*60
  return minutes

angular_speed_A = 360/12/60
angular_speed_B = 6

angle = abs((angular_speed_A - angular_speed_B)*clock_to_minutes(h,m)%360)

ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))

print(ans)

Solution (Python):
import math

A,B,H,M=map(int,input().split())

h=(360/12)*H+(360/12)*(M/60)
m=(360/60)*M

Hx=A*math.sin(math.radians(h))
Hy=A*math.cos(math.radians(h))

Mx=B*math.sin(math.radians(m))
My=B*math.cos(math.radians(m))

print(((Hx-Mx)**2+(Hy-My)**2)**(1/2))

Solution (Python):
import math
a,b,h,m = map(float, input().split()) 

h_kaku=(math.pi/6)*h
h_kaku+=(math.pi/360)*m
m_kaku=(math.pi/30)*m


h_x=a*math.cos(h_kaku)
h_y=a*math.sin(h_kaku)
m_x=b*math.cos(m_kaku)
m_y=b*math.sin(m_kaku)

ans=(h_x-m_x)**2+(h_y-m_y)**2

print(ans**(1/2))

Solution (Python):
a,b,h,m=map(int,input().split())
import math
mm=m*6
hh=(h*60+m)/2
ans=a**2+b**2-2*a*b*math.cos(math.radians(abs(hh-mm)))
print(math.sqrt(ans))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
degree = math.radians(abs((H * 60 + M) * 0.5 - M * 6))
print(((B * math.sin(degree)) ** 2 + (A - B * math.cos(degree)) ** 2) ** (1/2))

Solution (Python):
import math
def yogen(b,c,sita):
    a2 = b**2 + c**2 - 2*b*c*math.cos((sita/180)*math.pi)
    a = math.sqrt(a2)
    return a

def jisin(h,m):
    return 0.5*(m+h*60)

def hunsin(m):
    return 6*m

a,b,h,m = map(int,input().split())

print(yogen(a,b,jisin(h,m)-hunsin(m)))

Solution (Python):
import math
p=math.pi
A,B,H,M=map(int,input().split())
h=[A*math.cos(p*(H/6+M/360)),A*math.sin(p*(H/6+M/360))]
m=[B*math.cos(p*M/30),B*math.sin(p*M/30)]
L=math.sqrt(math.pow(h[0]-m[0],2)+math.pow(h[1]-m[1],2))
print(L)

Solution (Python):
import math

A, B, H, M = map(int, input().split())

H_angle = 30*H+0.5*M
M_angle = 6*M

angle = abs(H_angle-M_angle)
angle = min(angle, 360-angle)

ans = (A*A+B*B-2*A*B*math.cos(math.radians(angle)))**0.5
print(ans)

Solution (Python):
a,b,h,m = list(map(int,input().split()))
import math
pi = math.pi
l = (h+m/60)*2*pi/12
s = m*2*pi/60
theta = (l+s if l+s<2*pi else l-s)
ans = (a**2+b**2-2*a*b*math.cos(l-s))**(1/2)
print('{:.10f}'.format(ans))

Solution (Python):
from math import sqrt, radians, cos
a, b, h, m = map(int, input().split())
acc = (0.5 * m + h*30) - 6 * m
if acc > 180:
	acc = 360 - acc
ans = sqrt(a**2 + b**2 - 2*a*b*cos(radians(acc)))
print(ans)

Solution (Python):
from math import cos,sin,pi
a,b,h,m=map(int,input().split())
c=h/12*2*pi+m/12/60*2*pi
d=m/60*2*pi
x1=a*cos(c)
y1=a*sin(c)
x2=b*cos(d)
y2=b*sin(d)
print(((x1-x2)**2+(y1-y2)**2)**.5)

Solution (Python):
import math

a, b, h, m = map(int, input().split())

theta_a = math.radians(30 * h + 0.5 * m)
theta_b = math.radians(6 * m)

x_a, y_a = a * math.cos(theta_a), a * math.sin(theta_a)
x_b, y_b = b * math.cos(theta_b), b * math.sin(theta_b)

length = ((x_a - x_b) ** 2 + (y_a - y_b) ** 2) ** (0.5)
print(length)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
Md=M*6
Hd=H*30+0.5*M

if Hd>Md:
    de=Hd-Md
else:
    de=Md-Hd
C=A**2+B**2-(2*A*B*float(math.cos(math.radians(de))))
C=float(C**0.5)
print(C)

Solution (Python):
import math
a,b,h,m = list(map(int,input().split()))

long_h = (60 * h + m) / 720
short_m = m / 60

angle = abs(long_h - short_m) * 360
if angle > 180:
  angle = 360 - angle

cos_x = math.cos(math.radians(angle))
ans = math.sqrt(a*a + b*b - 2*a*b*cos_x)
print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
hm = 60*h+m
hmd = math.pi*hm/360
md = math.pi*m/30

ax = a * math.cos(hmd)
ay = a * math.sin(hmd)
bx = b * math.cos(md)
by = b * math.sin(md)

print(((ax-bx)**2+(ay-by)**2)**(0.5))

Solution (Python):


import math

a, b, h, m = map(int, input().split())

theta = abs((1/30 - 1/360)*(60*h+m)*math.pi)
if theta > math.pi:
  theta = 2*math.pi - theta
  
ans = (a**2 + b**2 - 2*a*b*math.cos(theta))**(1/2)

print(ans)

Solution (Python):
import math
a,b,h,m = map(int, input().split())
print((a**2+b**2-2*a*b*math.cos(math.radians(30*h-5.5*m)))**0.5)

Solution (Python):
import math
a, b, h, m = map(int, input().split())

h_arg = (h/12)*360 + (m/60)*30
m_arg = (m/60)*360

ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(h_arg-m_arg)))
print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
angle = (30*H + M/2) - 6*M
if angle > 180:
  angle = 360 - angle

print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(abs(angle)))))

Solution (Python):
import math


hour_hand_speed = (2 * math.pi) / (12 * 60)
minute_hand_speed = (2 * math.pi) / 60

hour_hand, minute_hand, hour, minute = list(
    map(int, input().split())
)

elapsed_time = 60 * hour + minute

hour_hand_angle = elapsed_time * hour_hand_speed
minute_hand_angle = minute * minute_hand_speed

angle_btw_hour_minute = abs(hour_hand_angle - minute_hand_angle)

distance = math.sqrt(
    hour_hand**2 + minute_hand**2 - (2 * hour_hand * minute_hand * math.cos(angle_btw_hour_minute))
)

print(distance)

Solution (Python):
import math
L = list(map(int,input().split()))
a = L[0]
b = L[1]
H = L[2]
M = L[3]

angleshort = 360*(60*H+M)/720
anglelong = 360*M/60



theta = math.radians((anglelong-angleshort))
ans = (a*a+b*b-2*a*b* math.cos(theta))**0.5
print(ans)

Solution (Python):

import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = kakuH - kakuM
    
    ans =(A**2 + B**2 - 2*A*B*np.cos(kakuS*pai/180))**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    
    print(main())

Solution (Python):

import numpy as np
from math import *

def main():
    A, B, H, M = list(map(int, input().split()))
    pai = 3.1415926535897323846264338327950
    kakuH = H*360/12 + M*30/60
    kakuM = M*360/60
    kakuS = absolute(kakuH, kakuM)
    
    ans =(A**2 + B**2 - 2*A*B*cos(radians(kakuS)) )**(1/2)

    return ans

def absolute(a, b):
    if a>=b:
        if a-b>180:
            return 360-(a-b)
        else:
            return a-b
    else:
        if b-a>180:
            return 360-(b-a)
        else:
            return b-a

if __name__ == '__main__':
    
    print(main())

Solution (Python):
import math
a,b,h,m = map(int,input().split())

hl = h * 30 + 30 * (m / 60)
ml = m * 6

if ml == 0:
    c = 360 - hl
else:
    c = abs(hl - ml)

if c > 180:
    c = 360 - c

d = (a ** 2) + (b ** 2) - (2 * a * b * (math.cos(math.radians(c))))

print(math.sqrt(d))

Solution (Python):
import numpy as np
a,b,h,m = map(int,input().split())
m = h*60+m
deg_a = m*30/60%360
deg_b = m*6%360
deg = abs(deg_a - deg_b)
if deg>180: deg = 360-deg
S = (a**2+b**2-2*a*b*np.cos(deg/180*np.pi))**0.5

print(S)

Solution (Python):
from math import sin, cos, pi

A, B, H, M = map(int, input().split())
H, M = pi * (H + M / 60) / 6, pi * M / 30
XA, YA = A * sin(H), A * cos(H)
XB, YB = B * sin(M), B * cos(M)
print(((XA - XB) ** 2 + (YA - YB) ** 2) ** 0.5)

Solution (Python):
import math

a, b, h, m = map(int, input().split())


H =  ((h + m / 60) / 12) * (2 * math.pi)
M = (m / 60) * (2 * math.pi)

if M - H >= 0:
  print('{:.10f}'.format(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(M - H))))
else:
  print('{:.10f}'.format(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(H - M))))

Solution (Python):
import math

def Colon():

    num = list(map(int,input().split()))

    angle_1 = (num[2]/12.)*360. + (num[3]/(60.*12.))*360.

    angle_2 = (num[3]/60.)*360.
    
    length = math.sqrt(num[0]*num[0] + num[1]*num[1] - 2.*num[0]*num[1]*math.cos(math.radians(angle_2 - angle_1)))

    print(length)

if __name__ == '__main__':
    Colon()

Solution (Python):
A, B, H, M = map(int, input().split())

import math

M_rad = math.radians(360 * (M / 60))
H_rad = math.radians(30 * (M / 60) + 360 * (H / 12))

AB = abs(M_rad - H_rad)
ans = (A ** 2 + B ** 2 - 2 * A * B * math.cos(AB)) ** 0.5
print(ans)

Solution (Python):
A, B, H, M = map(int, input().split())

import math

M_rad = math.radians(360 * (M / 60))
H_rad = math.radians(30 * (M / 60) + 360 * (H / 12))

AB = abs(M_rad - H_rad)
tmp = A ** 2 + B ** 2 - 2 * A * B * math.cos(AB)
ans = math.pow(tmp, 1 / 2)
print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
dega = (60*H+M)*(360/(60*12))
degb = M*(360/60)
a = [A*math.cos(math.radians(dega)),A*math.sin(math.radians(dega))]
b = [B*math.cos(math.radians(degb)),B*math.sin(math.radians(degb))]
dir = ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
print(dir)

Solution (Python):
import sys 
import numpy as np
import math 

readline = sys.stdin.readline 

ABHM = readline().split() 
A = float(ABHM[0])
B = float(ABHM[1])
H = float(ABHM[2])
M = float(ABHM[3])


alpha = H + M/60 if H != 12 else M/60
beta = M/5

theta = abs(alpha - beta) * np.pi / 6 

x = np.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))

print('{:.20f}'.format(x))

Solution (Python):
a,b,h,m=map(int,input().split())
import math
angle=abs(360/12*h+360/12*m/60-360/60*m)
if angle>180:
    angle=360-angle
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angle))))

Solution (Python):
import math
a,b,h,m = list(map(int, input().split()))

def pos(h, m):
  t = h*60 + m
  ang_h = t/(12*60) * 2*math.pi
  ang_m = m/(60) * 2*math.pi
  
  ang = min(abs(ang_h - ang_m), 360 - abs(ang_h - ang_m))
  print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(ang)))

  

pos(h,m)

Solution (Python):
import math
a,b,h,m = map(int, input().split())
'''
最小単位: min
時針: 12h = 12*60 min で一周
分針: 1h  =    60 min で一周
H時M分における時針, 分針の角度を求める

余弦定理:
a = sqrt(b^2 + c^2 - 2bc*cos(th))
'''
pi = math.pi
t_min = h*60 + m
th_h = (t_min / 12 / 60) * 2 * pi
th_m = m/60 * 2 * pi

c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th_h - th_m))
print(c)

Solution (Python):
import math
S=input().split( )
a=int(S[0])
b=int(S[1])
h=int(S[2])
m=int(S[3])
t=30*h-11*m/2
c=math.cos(math.radians(t))
d=a**2+b**2-2*a*b*c
print(math.sqrt(d))

Solution (Python):
import math
pi = math.pi
A, B, H, M = map(int, input().split())


theta = 2 * pi * ((H * 60 + M) / (12 * 60) - M / 60)


ans2 = A * A + B * B - 2 * A * B * math.cos(theta)

ans = math.sqrt(ans2)

print(ans)

Solution (Python):
import math

pi = math.pi

A,B,H,M = map(int, input().split())

rad = pi * 2 * (( H *60 +M) / (12*60) - M /60 ) 

XX = A*A + B*B -2*A*B* math.cos(rad)

X = math.sqrt(XX)

print(X)

Solution (Python):
import numpy as np

A, B, H, M = map(int, input().split())

Aw = 2 * np.pi / 12 / 60
Bw = 2 * np.pi / 60
thetaA = Aw * (H * 60 + M)
thetaB = Bw * M



if thetaA > thetaB:
    ans = np.sqrt(A ** 2 + B ** 2 - 2 * A * B * np.cos(thetaA - thetaB))
elif thetaB > thetaA:
    ans = np.sqrt(A ** 2 + B ** 2 - 2 * A * B * np.cos(thetaB - thetaA))
else:
    ans = abs(A - B)

print(ans)

Solution (Python):
import sys,math
input = sys.stdin.readline

A,B,H,M=list(map(int,input().split()))
wth = 2*math.pi/12/60
whm = 2*math.pi/60
radh = (H*60+M)*wth
radm = M*whm
rad = radh-radm
print((A**2+B**2-2*A*B*math.cos(rad))**0.5)

Solution (Python):
import math
inlist=input("").split(" ")
a=int(inlist[0])
b=int(inlist[1])
h=int(inlist[2])
m=int(inlist[3])
sita1=h*30+0.5*m
sita2=m*6
sita=sita1-sita2
d=a**2+b**2-2*a*b*math.cos(math.radians(sita))
e=math.sqrt(d)
print(e)