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=(int(x) for x in input().split())
h=h+m/60
rad=math.radians(min(math.fabs(h-m/5),math.fabs(12-math.fabs(h-m/5)))*360/12)
print(math.sqrt(a*a+b*b-2*a*b*math.cos(rad)))

Solution (Python):
import math


def cosin_fomula(a, b, cos:float):
    c = a**2 + b**2 - 2*a*b*cos
    return math.sqrt(c)


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

short_m = 360 / 60
long_m = 360 / (12 * 60)

all_minute = H * 60 + M

degree_short = (short_m * all_minute) % 360
degree_long = (long_m * all_minute) % 360
degree_between = abs(degree_short - degree_long)
cos = math.cos(math.radians(degree_between))
print(cosin_fomula(A, B, cos))

Solution (Python):
import numpy as np
A, B,H,M = map(int,input().split())
time = H*60.0+M
long_w = 360.0/12/60
long_w = np.deg2rad(long_w)
short_w = 360.0/60
short_w =np.deg2rad(short_w)
long_x = A * np.cos(time*long_w)
long_y = A * np.sin(time*long_w)
short_x,short_y =B * np.cos(time*short_w),B * np.sin(time*short_w)
s = np.array([long_x, long_y])
t = np.array([short_x, short_y])
u = s-t
print(np.linalg.norm(u))

Solution (Python):
import math 
a,b,h,m=map(int,input().split())
short=30*h
long=m*6
short=short+m*0.5

short=short%360
long=long%360

kakudo=abs(long-short)
ans=a*a+b*b-2*a*b*math.cos(math.radians(kakudo))
print(math.sqrt(ans))

Solution (Python):
import math

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

a_angle = 30 * (H + M / 60)
b_angle = 6 * M

if a_angle == 0:
    a_angle = 360

if b_angle == 0:
    b_angle = 360

if abs(a_angle - b_angle) < abs(b_angle - a_angle):
    angle = abs(a_angle - b_angle)
else:
    angle = abs(b_angle - a_angle)



X = math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(angle))))

print(X)

Solution (Python):
import math

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


vel_A = 0.5
vel_A_hour = 30
vel_B = 6



H = H % 12
M = M % 60




angle_A = H * vel_A_hour
angle_B = M * vel_B


angle_A += vel_A * M




theta = max(angle_A, angle_B) - min(angle_A, angle_B)
theta = math.radians(theta)





d = pow(A, 2) + pow(B, 2) - 2 * A * B * math.cos(theta)
d = math.sqrt(d)

print(d)

Solution (Python):

import math


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


def m_degree(m):
    return m * 6


A, B, H, M = map(int, input().split(' '))
d = abs(h_degree(H, M) - m_degree(M))

if d == float(0):
    print(abs(A - B))

elif d == float(180):
    print(A + B)

else:
    if d > 180:
        d = 360 - d
    C2 = (A ** 2) + (B ** 2) - (2 * A * B * math.cos(math.radians(d)))
    print(math.sqrt(C2))

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

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


x = m * 6


y = (h * 30) + (m * (1 / 2))


z = abs(x - y)


ans = sqrt((a*a)+(b*b)-(2*a*b*cos(radians(z))))

print('{0:.20f}'.format(ans))

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

rb = h*(360/12) + m*1/2
ra = m*(360/60)

ang = abs(rb - ra)
if 360-ang<=180:
      ang = 360 - ang
      ang = math.radians(ang)
else:
      ang = math.radians(ang)

ans =  a**2 + b**2 - 2*a*b*(math.cos(ang))
print(math.sqrt(ans))

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

ha = 360/12*h + 360/12*m/60
ma = 360/60*m
da = 0
if abs(ha - ma) > 180:
  da = 360 - abs(ha - ma)
else:
  da = abs(ha - ma)

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

Solution (Python):
import math
a, b, h, m = list(map(int, input().split()))
ans = 0
h = (h + m / 60) * 30
m = m * 6

if h > m:
    if h - m < 180:
        ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(h - m)))
    elif h - m == 180:
        ans = a + b
    else:
        ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(360 - (h - m))))
elif h == m:
    ans = abs(a-b)
elif h < m:
    if m - h < 180:
        ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(m - h)))
    elif m - h == 180:
        ans = a + b
    else:
        ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(360 - (m - h))))

print(ans)

Solution (Python):
import math

A, B, H, M = [int(i) for i in input().split()]


minutes = (H * 60) + M
short_hand_angle = 0.5 * minutes
long_hand_angle = 6 * M

diff_angle = abs(short_hand_angle - long_hand_angle)
if diff_angle > 180 :
    diff_angle = 360 - diff_angle
    

if diff_angle == 90:
    c = A**2 + B**2
    c = math.sqrt(c)
elif diff_angle == 180:
    c = A + B
else :
    c = A**2 + B**2 - 2*A*B*math.cos(math.radians(diff_angle))
    c = math.sqrt(c)

print(c)

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

rb = h*(360/12) + m*1/2
ra = m*(360/60)

ang = abs(rb - ra)
if 360-ang<=180:
      ang = 360 - ang
      ang = math.radians(ang)
else:
      ang = math.radians(ang)

ans =  a**2 + b**2 - 2*a*b*(math.cos(ang))
print(math.sqrt(ans))

Solution (Python):
import math

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

d_h = (30 * h) + ((30 * m)/60)
d_m = (6 * m)

diff = abs(d_h - d_m)
'''if diff > 180 :
    diff -= 180'''

d2 = (a ** 2) + (b ** 2) - (2 * a * b * math.cos((diff/180) * math.pi))

d = (d2 ** 0.5)

print(d)

Solution (Python):
import math

a, b, h, m = map(int, input().split())
hh = 30*h
if m != 0:
  hh += (m/60)*30
mm = 6*m
xh = a * math.cos(math.radians(hh))
yh = a * math.sin(math.radians(hh))
xm = b * math.cos(math.radians(mm))
ym = b * math.sin(math.radians(mm))

disX = pow(xh-xm, 2)
disY = pow(yh-ym, 2)
print(math.sqrt(disX+disY))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
jishinnodo = 30 * h + 0.5 * m
bunshinnodo = m * 6
kakudo = abs(jishinnodo - bunshinnodo)
rad = math.radians(kakudo)
coskakudo = math.cos(rad)
shahennonijou = a ** 2 + b ** 2 - 2 * a * b * coskakudo
print(shahennonijou**0.5)

Solution (Python):
import math

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

kakudo = abs(30 * H + 0.5 * M - 6 * M)

Cnijou = (A ** 2 + B ** 2) - (2 * A * B * math.cos(math.radians(kakudo)))

print(math.sqrt(Cnijou))

Solution (Python):
import math

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

theta = abs((6*m) - (30*h)%360 - (0.5*m)%360)


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

Solution (Python):
import math

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

R = 5.5 * (H * 60 + M)
C = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(R))
C = math.sqrt(C)
print(C)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
hh=h/12*360 + m/60*30
mh=m/60*360 


x=abs(hh-mh)
if x==180:
    print(a+b)

else:
    

    print ('%.9f'%(a**2+b**2-(2*a*b*math.cos(x*math.pi/180)))**0.5)

Solution (Python):
import math
a, b, h, m = (int(x) for x in input().split())
min = h * 60 + m
angle1 = ((360 / 720) * min) * (math.pi / 180)
angle2 = ((360 / 60) * m) * (math.pi / 180)
angle = abs(angle1 - angle2)
length = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(angle))
print(length)

Solution (Python):
import math
a,b,h,m = [int(x) for x in input().split()]

choshin = m*6
tanshin = (30*h) + m/2
d = abs(choshin-tanshin)
c = a**2 + b**2 -2*a*b*math.cos(math.radians(d))
print(math.sqrt(c))

Solution (Python):
import math
A, B, H, M = map(float,input().split())
H = H * 30 + M / 2
M = M * 6
C = abs(H - M)
if C == 0:
  print(A-B)
elif C == 180:
  print(A+B)
else:
  if C > 180:
    C = 360 - C
  print(math.sqrt(A**2 + B**2 - 2*A*B * math.cos(math.radians(C))))

Solution (Python):
import math
import decimal
def main():
    decimal.getcontext().prec = 20
    A,B,H,M = map(decimal.Decimal, map('{:.020f}'.format, map(int, input().split())))
    h = decimal.Decimal(360*H/12 + 30*M/60)
    m = decimal.Decimal(360*M/60)
    theta = decimal.Decimal(min(abs(h-m), abs(360-(h-m))))
    cos = decimal.Decimal(math.cos(math.radians(theta)))
    ans = decimal.Decimal(math.sqrt(A*A+B*B-2*A*B*cos))
    print(ans)

main()

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

a_ = 30*h+0.5*m
b_ = 6*m
c = abs(a_-b_)

print(pow(a**2+b**2-(2*a*b*math.cos(math.radians(c))), 0.5))

Solution (Python):
import math

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

h_rad = 30*h
h_rad += m*0.5
m_rad = 6*m
diff1 = abs(h_rad-m_rad)

diff2 = 360-diff1

diff = min(diff1,diff2)


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

Solution (Python):
import math

A, B, H, M = map(int, input().split())
hours = (H * 60 + M) / 60
h_unit = 2 * math.pi / 12
m_unit = 2 * math.pi / 60
a_x = A * math.cos(hours * h_unit)
a_y = A * math.sin(hours * h_unit)
b_x = B * math.cos(M * m_unit)
b_y = B * math.sin(M * m_unit)

print(math.sqrt(math.pow(a_x - b_x, 2) + math.pow(a_y - b_y, 2)))

Solution (Python):
A,B,H,M=map(int,input().split())
N=abs(H*30+M*0.5-M*6)
if N >= 180 :
    N=360-N
import math
ans2=A**2+B**2-2*A*B*math.cos((math.radians(N)))

ans=math.sqrt(ans2)
print(ans)

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

angle = (M * pi)/360 + (H * pi)/6 - (M * pi)/30

X = A**2 + B**2 - 2 * A * B * math.cos(angle)

ans = math.sqrt(X)
print(ans)

Solution (Python):
import math

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


D =A[0]**2+A[1]**2-2*A[0]*A[1]*math.cos(math.radians(30*A[2]-5.5*A[3]))

print(math.sqrt(D))

Solution (Python):
import numpy as np

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

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

        theta = abs(A_angle-B_angle)

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

        print("{}".format(ans))

if __name__=="__main__":
        main()

Solution (Python):
import math
a,b,h,m = map(int,input().split())
if m==0 and h==0:
	print(a-b)
elif m==0 and h==6:
	print(a+b)
else:
	p=math.pi/2
	x_a= a*math.cos(p-m*2*math.pi/60)
	y_a = a*math.sin(p-m*2*math.pi/60)
	x_b= b*math.cos(p-(h+m/60)*2*math.pi/12)
	y_b = b*math.sin(p-(h+m/60)*2*math.pi/12)
	L = math.sqrt((x_a-x_b)**2+(y_a-y_b)**2)
	print(L)

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

tanshin_kakudo = (360/12) * H + (360/12)/60 * M
tyoushin_kakudo = (360/60) * M
kakudo_sub = abs(tanshin_kakudo-tyoushin_kakudo)
print(math.sqrt((A**2)+(B**2)-2*A*B*math.cos(math.radians(kakudo_sub))))

Solution (Python):
import math
import numpy

A,B,H,M = (int(x) for x in input().split())

if (H * 30) - (5.5 * M) >= 0:
    a = (H * 30) - (5.5 * M)
else:
    a = (5.5 * M) - (H * 30)

c = A**2 + B**2 - 2 * A * B * math.cos(math.radians(a))

c = math.sqrt(c)

print(c)

Solution (Python):



import math
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

A, B, H, M = [int(_) for _ in input().split()]

l =  (0.5 * (H * 60 + M) ) % 360 
s =  360 / 60 * M

sita = abs(max(s, l) - min(s, l))
c = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(sita)))
print(c)

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

Hour = A*cmath.exp(((2*(60*H+M)/(12*60))-1/4.0)*cmath.pi*1j)
Min = B*cmath.exp((2*(M/60)-1/4.0)*cmath.pi*1j)

print(math.sqrt((Hour.real-Min.real)**2+(Hour.imag-Min.imag)**2))

Solution (Python):
import math

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

HH = H * 5

angle = (HH - M) * 6 + (M / 60) * 30

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

Solution (Python):
import math
def calcAngle(h,m):
    if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
    return angle 
a,b,h,m=map(int,input().split())
angle=math.cos(math.radians(calcAngle(h,m)))
length=math.sqrt(a**2+b**2-2*a*b*angle)
print(length)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
alpha = abs(H + M / 60 - M / 5)

if 6 < alpha:
    alpha = 12 - alpha

print(math.sqrt(A ** 2 + B ** 2 - (math.cos(alpha * math.pi / 6) * 2 * A * B)))

Solution (Python):
from math import *
ip=[int(x) for x in input().split()]

a=ip[0]
b=ip[1]
h=ip[2]
m=ip[3]
hd=h*30+m*30/60
md=(m//5)*30+(m%5)*30/5

x=abs(hd-md)

ans=a*a+b*b-2*a*b*cos(radians(x))

ans=sqrt(ans)
ans=round(ans,20)
f=str(ans)
for i in range(len(f)):
	if f[i]=='.':
		l=i
		break
l=len(f)-l
for i in range(l,20):
	f+='0'

print(f)

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

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

dg_tmp = abs(30*h - 11*m/2)
dg = min(dg_tmp, 360-dg_tmp)
r_dg = radians(dg)

c = a**2 + b**2 - 2*a*b*cos(r_dg)

print(c**(1/2))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
angule_h = 30 * h + 0.5 * m
angule_m = 6 * m
angule_diff = min(360 - abs(angule_h - angule_m),abs(angule_h - angule_m))
c_2 = (a ** 2 + b ** 2) - (2 * a * b * math.cos(math.radians(angule_diff)))
print(math.sqrt(c_2))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
R1=(H*60+M)*(0.5)
R2=M*6
R=R1-R2
R=abs(R)
if(R>180):
  R=360-R
COS=math.cos(math.radians(R))
ans=A**2+B**2-2*A*B*COS
print(ans**(1/2))

Solution (Python):
import math

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

h = math.pi / 6 * (H + M / 60)

m = math.pi / 30 * M

if abs(h-m) <= math.pi:
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(abs(h-m)))
else:
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(-abs(h-m)))

print(ans)

Solution (Python):
import math

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

theta = abs(6 * m - (h * 60 + m) / 2)

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

Solution (Python):
import math

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

mk = m*6
hk = h*30+(m/60)*30

t = abs(mk-hk)

theta = t/180*math.pi

aa = (math.sin(theta)*a)**2
if t > 90:
    bb = (b + (math.cos(theta)) * a) ** 2
else:
    bb = (b - (math.cos(theta)) * a) ** 2


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())
new_h=h+m/60
k=new_h/12*360*math.pi/180
s=m/60*360*math.pi/180
L=[a*math.cos(k),a*math.sin(k)]
l=[b*math.cos(s),b*math.sin(s)]
x1=L[0]
y1=L[1]
x2=l[0]
y2=l[1]
long=math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(long)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
H_an = H * 360 /12 + M / 2
M_an = M * 360 /60 
an = abs(H_an - M_an)
if an >= 180:
    an = 360 - an
an = an * math.pi/180

a = (A**2) + (B**2) - (2*A*B*math.cos(an))
print(math.sqrt(a))

Solution (Python):
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right

t=1
for _ in range(t):
    
    a,b,h,m=map(int,stdin.readline().split())
    hang=(h)*30+(m*0.5)
    mang=m*6
    ang=abs(hang-mang)
    
    
    
    ang=math.radians(ang)
    ans=math.sqrt((a*a)+(b*b)-(2*a*b*math.cos(ang)))
    print(ans)

Solution (Python):
import numpy as np
A,B,H,M = (int(x) for x in input().split())
argA = 30*H + 0.5*M
argB = 6*M
if argA>argB:
    arg = argA-argB
else:
    arg = argB-argA
    
if arg > 180:
    arg = 360 - arg
    
cc = A**2 + B**2 -2*A*B*np.cos((arg/180)*np.pi)
c = np.sqrt(cc)

print(c)

Solution (Python):









import os
import sys
import math




def main():
    a,b,h,m = map(int,input().split())
    angle = math.radians(30*h+0.5*m-6*m)
    cos_angle = math.cos(angle)
    x_2 = a**2+b**2-2*a*b*cos_angle
    print(math.sqrt(x_2))
    return 

if __name__ == "__main__":
    main()

Solution (Python):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd, cos, radians
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    a, b, h, m = i_map()

    minitus = 6 * m
    hours = 30 * h + 0.5 * m

    if abs(hours-minitus) > 180:
        theta = 360 - abs(hours-minitus)
    else:
        theta = abs(hours-minitus)

    ans2 = pow(a,2) + pow(b,2) - 2 * a * b * cos(radians(theta))

    print(pow(ans2,0.5))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from math import cos, radians, sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b, h, m = MAP()

hm = h*60 + m

heach = hm / 720
meach = m / 60
hdig = heach * 360
mdig = meach * 360
dig = min(abs(hdig-mdig), 360 - abs(hdig-mdig))

ans = sqrt(a**2 + b**2 -(2*a*b*cos(radians(dig))))
print(ans)

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


def get_result(data):
    A, B, H, M = data
    h_deg = (H + M/60.0) * 30.0
    m_deg = M * 6.0
    theta = math.radians(abs(m_deg-h_deg))
    ans = np.sqrt(np.float128(A**2+B**2 - 2*A*B*math.cos(theta)))
    return ans


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip().split(' ')))
    result = get_result(data)
    print(result)

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

k = 30 * H + 0.5 * M - 6 * M
y = math.cos(math.radians(k))
print(math.sqrt(A*A + B*B - 2*A*B*y))

Solution (Python):
import math

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

radians = (abs((h * 60 + m) / (60 * 12) * 360 - m / 60 * 360))

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

print(len)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
degB=m*math.pi/30
degA=(60*h+m)*math.pi/360
degAB=max(degA,degB)-min(degA,degB)

ans=math.sqrt(a**2+b**2-2*a*b*math.cos(degAB))
print(ans)

Solution (Python):
import math

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

one = (h / 12)
two = (m / 60)
one += two / 12

r = abs(one - two) * 360


if r > 180:
  r = 360 - r



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

Solution (Python):
import numpy as np
a,b,h,m=map(int,input().split())
pi=np.pi
h_deg=(1/6)*pi*h+(1/360)*pi*m
m_deg=(1/30)*pi*m
deg=abs(m_deg-h_deg)
if(deg>pi):
    deg=2*pi-deg
else:
    pass
c=a**2+b**2-2*a*b*np.cos(deg)
print(c**(1/2))

Solution (Python):
a,b,h,m = map(int,input().split())
import math
x = math.pi*(h - 11*m/60)/6
print((a**2 + b**2 -2*a*b*math.cos(x))**0.5)

Solution (Python):
import math



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

JI=H*30+M/2
FUN=6*M

XJI=A*math.sin(math.radians(JI))
YJI=A*math.cos(math.radians(JI))
XFUN=B*math.sin(math.radians(FUN))
YFUN=B*math.cos(math.radians(FUN))

ans=(XJI-XFUN)**2+(YJI-YFUN)**2
print(math.sqrt(ans))

Solution (Python):
a,b,h,m=list(map(int,input().split()))
hun=h*60+m
kakudo=min((5.5*hun)%360,360-(5.5*hun)%360)
import math
cos=math.cos(math.radians(kakudo))
print(math.sqrt(a*a+b*b-2*a*b*cos))

Solution (Python):
import math
A , B, H, M = map(int, input().split())
long = (M * 360) / 60
short = (H * 60 + M) * 360 / (12 * 60)
deg = short - long

E = A**2 + B**2 - 2 * A * B * math.cos(math.radians(deg))
print(math.sqrt(E))

Solution (Python):
import math
A, B, H, M = map(int,input().split())
k = 0.5*(60*H + M) - 6*M
l = abs(k)

if l <= 180:
    c = math.radians(l)
    C = math.cos(c)
    Q = math.sqrt(A**2 + B**2 - 2*A*B*C)
    print(Q)
else:
    w = 360-l
    c = math.radians(w)
    C =math.cos(c)
    Q = math.sqrt(A**2 + B**2 - 2*A*B*C)
    print(Q)

Solution (Python):
import numpy,math

a,b,h,m = map(lambda x: int(x) ,input().split(" "))

minutes = 60 * h + m

thetal = m * 6
thetas = minutes * 0.5

theta = float(abs(thetal - thetas))
if(theta > 180):
    theta = 360 - theta

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

print(dist)

Solution (Python):
import math
A, B, H, M = map(float,input().split())
rad2 = 360 * (H + M/60) / 12
rad1 = 360 * M / 60
if rad2 > rad1:
    rad = rad2 - rad1


else:
    rad = rad1 - rad2
if rad > 180:
    rad = 360 - rad
len = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(rad)))
print(len)

Solution (Python):
import numpy as np

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

a = i[0]
b = i[1]
h = i[2]
m = i[3]

theta = (abs(30 * h - 5.5 * m) % 360) * (np.pi / 180)

print(np.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta)))

Solution (Python):
import math
import numpy as np

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

A = np.array([a*math.sin(math.radians(360*h/12 + 30*m/60)), a*math.cos(math.radians(360*h/12 + 30*m/60))])
B = np.array([b*math.sin(math.radians(360*m/60)), b*math.cos(math.radians(360*m/60))])

print(math.sqrt(sum(A**2) + sum(B**2) - 2*np.dot(A, B)))

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


phi = m * 6

theta = h * 30 + 0.5 * m

import math

apoint = (a*math.cos(math.radians(theta)), a*math.sin(math.radians(theta)))
bpoint = (b*math.cos(math.radians(phi)),   b*math.sin(math.radians(phi)))



xd = abs(apoint[0] - bpoint[0])
yd = abs(apoint[1] - bpoint[1])



ans = math.sqrt(math.pow(xd,2) + math.pow(yd,2))

print(ans)

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

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

degA = H * 30 + M * 0.5
degA = degA % 360
degB = H * 360 + M * 6
degB = degB % 360
xa, ya = math.sin(math.radians(degA)) * A, math.cos(math.radians(degA)) * A
xb, yb = math.sin(math.radians(degB)) * B, math.cos(math.radians(degB)) * B
ans = math.sqrt((xa - xb) ** 2 + (ya - yb) ** 2)
print(ans)

Solution (Python):

import math

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

hour = (60 * H + M) / 2
minute = 6 * M
degree = abs(hour - minute)
nijou = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(degree))
print(math.sqrt(nijou))

Solution (Python):
import math as mt
A,B,H,W = [int(x) for x in input().split(' ')]

ha = mt.pi * 2 / 12 * H + mt.pi * 2 / 12 * (W/60)
ma = mt.pi * 2 / 60 * W
da = ha-ma

dist = mt.sqrt(A**2 + B**2 - 2*A*B*mt.cos(da))

print(dist)

Solution (Python):
import numpy as np

raw = input()
a, b, h, m = [int(f) for f in raw.split(" ")]

hour = np.array(
    [a * np.sin(h * np.pi / 6 + m * np.pi / 360), a * np.cos(h * np.pi / 6 + m * np.pi / 360)]
)
mins = np.array([b * np.sin(m * np.pi / 30), b * np.cos(m * np.pi / 30)])

r = np.linalg.norm(hour - mins)

print(r)

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

angle_A = (H + M/60)* 30
angle_B = M * 6
angle = angle_A - angle_B
if abs(angle) <= 180:
  print((A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(angle))) ** (1/2))
else:
  angle = 360 - angle
  print((A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(angle))) ** (1/2))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
h_angle = 360 * M / 60
j_angle = 360 * (H * 60 + M) / (12 * 60)
angle = min(abs(h_angle - j_angle), 360-abs(h_angle - j_angle))
ans = (A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(angle))) ** 0.5
print(ans)

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


phi = m * 6

theta = h * 30 + 0.5 * m

import math

apoint = (a*math.cos(math.radians(theta)), a*math.sin(math.radians(theta)))
bpoint = (b*math.cos(math.radians(phi)),   b*math.sin(math.radians(phi)))



xd = abs(apoint[0] - bpoint[0])
yd = abs(apoint[1] - bpoint[1])



ans = math.sqrt(math.pow(xd,2) + math.pow(yd,2))

print(ans)

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

mnt = 60 * H + M

arg_A = (mnt % 720) * 0.5
arg_B = (mnt % 60) * 6



if arg_A == arg_B:
  print(abs(B-A))
  sys.exit()
elif abs(arg_A-arg_B) == 180:
  print(A+B)
  sys.exit()

big = max(arg_A, arg_B)
small = min(arg_A, arg_B)
w = big - small

if w > 180:
  w = 360 - w

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

print(ans)

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

theta_A = math.pi / 6 * (H + M / 60)
theta_B = math.pi / 30 * M
theta = abs(theta_A - theta_B)

if theta > math.pi:
  theta = 2 * math.pi - theta

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

print(L)

Solution (Python):
import math

L = input().split()
A = int(L[0])
B = int(L[1])
H = int(L[2])
M = int(L[3])


rad_A = H * 30 + M * 0.5
rad_B = M * 6

rad = rad_A - rad_B
if rad > 180:
    rad = 360 - rad

cos_num = math.cos(math.radians(rad))


x_squared = A**2 + B**2 - (2 * A * B * cos_num)
ans = math.sqrt(x_squared)

print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
a1=(h/12)*360+(m/60)*30
b1=(m/60)*360
if abs(b1-a1)==0:
    print(abs(a-b))
elif abs(b1-a1)<180:
    s=math.radians(abs(b1-a1))
    c=a**2+b**2-2*a*b*math.cos(s)
    print(c**(1/2))
elif abs(b1-a1)==180:
    print(a+b)
else:
    s=math.radians(360-abs(b1-a1))
    c=a**2+b**2-2*a*b*math.cos(s)
    print(c**(1/2))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
time = h * 60 + m
px = a * math.sin(math.radians(time / 2))
py = a * math.cos(math.radians(time / 2))
cx = b * math.sin(math.radians(m * 6))
cy = b * math.cos(math.radians(m * 6))
print(((px - cx) ** 2 + (py - cy) ** 2) ** 0.5)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
if 0 < abs(0.5*(60*H+M) - 6*M) <180:
    ans = A**2 + B**2 -2*A*B*math.cos(math.radians(abs(0.5*(60*H+M) - 6*M)))
    ans**=(1/2)
elif abs(0.5*(60*H+M) - 6*M)==0:
    ans = abs(A-B)
elif abs(0.5*(60*H+M) - 6*M)==180:
    ans= A+B
else:
    ans= A**2 + B**2 -2*A*B*math.cos(math.radians(360-abs(0.5*(60*H+M) - 6*M)))
    ans**=(1/2)
print(ans)

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

theta = abs((h*30 + 0.5*m) -6 * m)

theta = min(theta, 360-theta)

raji = math.radians(theta)

tmp = 2*a*b*math.cos(raji)

ans = a**2 + b**2 - tmp
ans = math.sqrt(ans)

print(ans)

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

Asin=(360*((H/12)+(1/12)*(M/60)))
x1=A*(math.cos(math.radians(Asin)))
y1=A*(math.sin(math.radians(Asin)))

Bsin=(360*(M/60))
x2=B*(math.cos(math.radians(Bsin)))
y2=B*(math.sin(math.radians(Bsin)))

Z=((((x1)-(x2))**2)+(((y1)-(y2))**2))**(1/2)
print(Z)

Solution (Python):
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
import math

a,b,h,m=map(int,input().split())
nowh=30*h+(30/60)*m
nowm=6*m

if nowh==nowm:
    print(max(a,b)-min(a,b))
    exit()
if nowh==0:
    nowm=min(nowm,360-nowm)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowm)))**0.5)
elif nowm==0:
    nowh=min(nowh,360-nowh)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowh)))**0.5)
else:
    now=max(nowh,nowm)-min(nowh,nowm)
    
    
    print((a**2+b**2-2*a*b*math.cos(math.radians(now)))**0.5)

Solution (Python):
import numpy as np
from numpy import linalg as LA

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

def rotation(x, t, deg = False):
    if deg == True:
        t = np.deg2rad(t)
    a = np.array([[np.cos(t), -np.sin(t)], [np.sin(t),  np.cos(t)]])
    ax = np.matmul(a, x)        
    return ax
vec_a, vec_b = np.array([[A], [0]]), np.array([[B], [0]])

rot_a = rotation(vec_a,  -(360 * H) / 12 - 30 * (M / 60), True)
rot_b = rotation(vec_b, -(360 * M) / 60, True)




print(LA.norm(rot_a - rot_b))

Solution (Python):
import math
pi = math.pi
a, b, h, m = map(int, input().split())
minute = 60 * h + m
jisin = (2*pi)/(12*60) * minute
hunsin = (2*pi)/60 * minute
kakudo = abs(jisin - hunsin)
while kakudo >= 2 * pi:
    kakudo -= 2 * pi
coskakudo = math.cos(kakudo)
ans = (a**2 + b**2 - 2*a*b*coskakudo) ** 0.5
print(ans)

Solution (Python):
import  math
hour_hari , minute_hari , hour , minute = map(int,input().split())
hour *= 5.0
hour_deg = 6*hour
hour_deg += 0.5*minute
minute_deg = 6*minute
hour_rad = math.radians(hour_deg)
minute_rad = math.radians(minute_deg)
if hour_rad >= minute_rad :
    dif_rad = hour_rad - minute_rad
    if dif_rad > math.pi :
        dif_rad = 2*math.pi - dif_rad
    hari_cos = math.cos(dif_rad)
    x_2_jou = hour_hari*hour_hari + minute_hari*minute_hari \
              - 2*hour_hari*minute_hari*hari_cos
    print(math.sqrt(x_2_jou))
else :
    dif_rad = minute_rad - hour_rad
    if dif_rad > math.pi :
        dif_rad = 2*math.pi - dif_rad
    hari_cos = math.cos(dif_rad)
    x_2_jou = hour_hari * hour_hari + minute_hari * minute_hari \
              - 2 * hour_hari * minute_hari * hari_cos
    print(math.sqrt(x_2_jou))

Solution (Python):
import math

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

degree_h = ((H + M / 60) * 30) % 360
degree_m = ((H * 60 + M) * 6) % 360

deg = (
    min(abs(degree_h - degree_m), 360 - abs(degree_h - degree_m)) * 2 * (math.pi / 360)
)

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(deg)))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
A_sin=A*math.sin(2*math.pi*(60*H+M)/720)
A_cou=A*math.cos(2*math.pi*(60*H+M)/720)
B_sin=B*math.sin(2*math.pi*(M/60))
B_cos=B*math.cos(2*math.pi*(M/60))
ans=math.sqrt((A_sin-B_sin)**2+(A_cou-B_cos)**2)
print(ans)

Solution (Python):
import math





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


H_angle = H * 30 + (M / 60 * 30)

M_angle = M * 6


H_M_angle = abs(H_angle - M_angle)

cosHM = math.cos(math.radians(H_M_angle))

C2 = A**2 + B**2 - 2*A*B*cosHM

print(math.sqrt(C2))

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

ans = 0

m_r = m/5

h_r = h + m/60


reg = (h_r - m_r)/12*360
ans = math.sqrt(a**2 + b**2 -2*a*b*math.cos(math.radians(reg)))

print(ans)