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())
rad = ((60 * h - 11 * m) * math.pi) / 360
cos = math.cos(rad)
c2 = (a ** 2) + (b ** 2) - 2 * a * b * cos
ans = math.sqrt(c2)
print(ans)

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

if abs(H*30+M*0.5-M*6)<=180:
    C=A**2+B**2-2*A*B*math.cos(math.radians(abs(H*30+M*0.5-M*6)))
    print(math.sqrt(C))
else:
    C=A**2+B**2-2*A*B*math.cos(math.radians((360-abs(H*30+M*0.5-M*6))))
    print(math.sqrt(C))

Solution (Python):
import math

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

h = H * 30 + M * 0.5
m = M * 6
rad = min(h - m, m - h)

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

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

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

arg_h = 30*h + 30*(m/60)
arg_m = 6*m
if abs(arg_h-arg_m) < 180:
    arg = math.radians(abs(arg_h-arg_m))
    ans = (a**2+b**2-2*a*b*math.cos(arg))**(1/2)
elif abs(arg_h-arg_m) == 180:
    ans = a+b
else:
    arg = math.radians(360-abs(arg_h-arg_m)) 
    ans = (a**2+b**2-2*a*b*math.cos(arg))**(1/2)



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

Solution (Python):
import math

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

H = (H*360/12)+(M*30/60)
M = M*360/60

a = abs(H-M)

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

Solution (Python):
import math
A,B,H,M = map(int,input().split())
HR = (M * 360)/60
MR = (H * 60 + M)*360/(12*60)
d = abs(MR - HR)
if(H == 5*M):
    print(str(abs(B-A)))
else:
    ans = ((A**2 + B**2) - (2*A*B*math.cos(math.radians(d))))**(1/2)
    print(str(ans))

Solution (Python):
import math
A, B, H, M = map( int, input().split() )
pi = math.pi
thetaA = math.radians(  M * 6   )
thetaB = math.radians(  ( 60 * H + M ) / 2)
xa = A * math.cos( thetaA )
ya = A * math.sin( thetaA )
 
xb = B * math.cos( thetaB )
yb = B * math.sin( thetaB )
 
print( math.sqrt( ( xa - xb ) ** 2 + ( ya - yb ) ** 2 ) )

Solution (Python):
import math
i = list(map(int,input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]
thete = 6*m - (30*h+m/2)
if thete<0:
    thete = thete*(-1)
if thete > 180:
    thete = 360 - thete
cos = math.cos(math.radians(thete))
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())

H = H*5 + (5/60)*M

comp = abs(H-M)

if(comp>=30):
    comp = 60-comp

pre = ((comp*6)/360)*2*math.pi

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

print(math.sqrt(ans))

Solution (Python):
import math

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

def calc_ans(rad):
    x = a**2 + b**2 -2*a*b*math.cos(rad)
    ans = math.sqrt(x)
    return ans

l_w = 2*math.pi/(12*60)
s_w = 2*math.pi/60

long_rad = l_w * (h*60+m)
short_rad = s_w * m

if abs(long_rad-short_rad) >= math.pi:
    rad = 2*math.pi-abs(long_rad-short_rad)
else:
    rad = abs(long_rad-short_rad)

ans = calc_ans(rad)
print(ans)

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




import math
'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
a,b,h,m=map(int, input().split())
if m!=0:
    arga=360*(h/12+m/(60*12))
    argb=360*(m/60)
else:
    arga=360*(h/12)
    argb=360

if m==0 and h==0:
    print("{:.10f}".format(float(abs(b-a))))
else:
    
    
    
    c=(b**2+a**2-2*a*b*round(math.cos(math.radians(argb-arga)),20))**(1/2)
    print(c)
    a=input()

Solution (Python):
import math

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

h = H * 30 + M * 0.5
m = M * 6

s = min(360 - abs(h - m), abs(h - m))

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

print(ans)

Solution (Python):
import math
 
A,B,H,M = map(int,input().split())
 
w_long = 0.5
w_short = 6
 
minute = H * 60 + M
 
R_long = minute * w_long
R_short = M * w_short
 
R = abs(R_long-R_short)
 
if R == 0 or R == 360:
    print(abs(A-B))
elif R == 180:
    print(A+B)
else:
	cosR = math.cos(math.radians(R))
 
	ans2 = A**2 + B**2 - 2*A*B*cosR
	print(math.sqrt(ans2))

Solution (Python):
import numpy as np
a, b, h, m = map(int, input().split())
h_a = ((h % 12) + m / 60)*360 / 12
m_b = ((m % 60)*360/60)%360
angle = min(np.abs(h_a - m_b), 360 - np.abs(h_a - m_b))
print(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(np.radians(angle))))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
rad_long = (h * 60 + m) / (60) * 2 * math.pi
rad_short = (h * 60 + m) / (12 * 60) * 2 * math.pi

x_long, y_long = b * math.cos(rad_long), b * math.sin(rad_long)
x_short, y_short = a * math.cos(rad_short), a * math.sin(rad_short)

dis = ((x_long - x_short)**2 + (y_long - y_short)**2)**0.5
print(dis)

Solution (Python):

import math

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

theta_A = H * 30 + M/2
theta_B = 6*M

theta_test = abs(theta_A - theta_B)
theta = min(theta_test, 360 - theta_test)

cos = math.cos(math.radians(theta))

test = A**2 + B**2 - 2*A*B*cos

print(math.sqrt(test))

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

hr = h*30+m/2
mr = m*6
r = abs(hr-mr)
r = min(r, 360-r)

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

print(math.sqrt(ans))

Solution (Python):


import math

temp = input().split(" ")

al = int(temp[0])
bl = int(temp[1])
h = int(temp[2])
m = int(temp[3])



a = ((h * 60 + m) / 720) * 2 * math.pi
b = (m / 60) * 2 * math.pi

cax = al * math.cos(a)
cay = al * math.sin(a)
cbx = bl * math.cos(b)
cby = bl * math.sin(b)




length = pow((cax - cbx), 2) + pow((cay - cby), 2)
length = math.sqrt(length)

print(length)

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

mi = 6*m
ho = 30*h+m/2
t = abs(ho-mi)
t *=p
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(t/180))
print('{:.18f}'.format(ans))

Solution (Python):
import numpy as np

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

deg_H = H*np.pi/6+np.pi/6/60*M
deg_M = np.pi/30*M

theta = deg_H-deg_M

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

Solution (Python):
import sys
import math

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

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

z_x_j = math.sin(math.radians(j)) * A
z_y_j = math.cos(math.radians(j)) * A
z_x_h = math.sin(math.radians(h)) * B
z_y_h = math.cos(math.radians(h)) * B

print(math.sqrt((z_x_j - z_x_h) ** 2 + (z_y_j - z_y_h) ** 2 ))

Solution (Python):
import math

B, A, H, M = map(int,input().split())
m = (M/60) * 360
h = ((30*H + 0.5*M)/360) * 360


if abs(m-h) > 180:
    theta = 360 - abs(m-h)
else:
    theta = abs(m-h)

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

Solution (Python):
import math
def main():
    A,B,H,M= map(float, input().split())
    mkaku = M*6
    hkaku = H*30+M*0.5
    Co = abs(mkaku-hkaku)
    if Co > 180:
        Co = 360 - Co
    ans2 = A*A + B*B - 2*A*B*math.cos(math.radians(Co))
    print (math.sqrt(ans2))

if __name__ == '__main__':
    main()

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

rad_h = 2*np.pi-(np.pi/360)*time
rad_m = 2*np.pi-(np.pi/30)*M

A_x = A*np.cos(rad_h)
A_y = A*np.sin(rad_h)
B_x = B*np.cos(rad_m)
B_y = B*np.sin(rad_m)

v = np.array([A_x-B_x,A_y-B_y])

l = np.linalg.norm(v)
  
print(l)

Solution (Python):
import math

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


h=h*30+0.5*m
m*=6
x=min(abs(h-m),360-abs(h-m))
y=math.cos(math.radians(x))

if x==1:
    print(0)
else:
    print(math.sqrt(a**2+b**2-2*a*b*y))

Solution (Python):
import math

input_line = input().split()
a = float(input_line[0])
b = float(input_line[1])
h = float(input_line[2]) + float(input_line[3]) / 60.0
m = float(input_line[3])

hour = [a * math.cos((3.0-h) / 6.0 * math.pi), a * math.sin((3.0-h) / 6.0 * math.pi)]
minute = [b * math.cos((15.0-m) / 30.0 * math.pi), b * math.sin((15.0-m) / 30.0 * math.pi)]

d = math.sqrt((minute[0]-hour[0])**2 + (minute[1]-hour[1])**2)

print(d)

Solution (Python):
import math

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

HC = H*0.5*60 + 0.5*M
MC = M*6




if MC-HC >= 0:
    CC = MC-HC

else:
    CC = HC-MC
    


T = (A**2 + B**2 - 2*A*B*math.cos(math.radians(CC)))**(1/2)
print(T)

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

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

angle_m = 6 * m
angle_h = 30 * h + 0.5 * m
angle = abs(angle_m - angle_h)
if angle > 180:
  angle = 360 - angle

ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(angle)))
print('{:.20f}'.format(ans))

Solution (Python):
import math
if __name__ == "__main__":
    a, b, h, m = map(float, input().split())
    zi_deg = (60.0 * h + m) / 2
    hu_deg = 6.0 * m
    sa = abs(zi_deg - hu_deg)
    ans = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(sa))
    print(math.sqrt(ans))

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

if(h>m):rad=min(abs(h-m),abs((360-h)+m))
else:rad=min(abs(m-h),abs((360-m)+h))

c= pow(a,2)+pow(b,2)-2*a*b*np.cos(np.pi*2*(rad/360))
print(math.sqrt(c))

Solution (Python):
import numpy as np 

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

h_deg = 30 * h + 0.5 * m
m_deg = 6 * m
deg = h_deg-m_deg
if deg <= 180:
    ans = np.sqrt(a**2+b**2-2*a*b*np.cos(deg*np.pi/180))
else:
    deg = 360-deg
    ans = np.sqrt(a**2+b**2-2*a*b*np.cos(deg*np.pi/180))
print(ans)

Solution (Python):
import math

a, b, h, m = map(int,input().split())
s_a = m * 6.0;
s_b = (h * 360 / 12.0) + (m * 30 /60.0);
s_c = abs(s_a - s_b);
s_c = min(s_c,360-s_c)
ans =  a*a + b*b - 2*a*b*math.cos(s_c * math.pi /180.0);
print(math.sqrt(ans))

Solution (Python):
import math
A, B, H, M = [int(n) for n in input().split()]

def coord(r, theta):
    return math.cos(theta) * r, math.sin(theta) * r

pa = coord(A, (H+M/60)/6  * math.pi)
pb = coord(B, M/30 * math.pi)


print('{}'.format(math.sqrt( \
    (pa[0] - pb[0]) ** 2 +   \
    (pa[1] - pb[1]) ** 2     \
)))

Solution (Python):
import math
import numpy as np
def calc(h,m): 
    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=calc(h,m)
theta1=np.deg2rad(angle)
side = (a*a) + (b*b) - 2*a*b*math.cos(theta1)
print(math.sqrt(side))

Solution (Python):
import math
def findAngle(h,m):
	hour=(h*360)/12+(m*360)/(12*60)
	mint=(m*360)/60
	angle=abs(hour-mint)
	if(angle>180):
		angle=360-angle
	return angle
def dist(a,b,h,m):
  x=a**2+b**2-2*a*b*math.cos(math.radians(findAngle(h,m)))
  return x**0.5
a,b,h,m=map(int,input().split())
print(dist(a,b,h,m))

Solution (Python):
import math

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

theta = abs(5*(h+m/60) - m) * math.pi / 30

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

print(c)

Solution (Python):
import math

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

S=(H/12)*360+(M/60)*(360/12)
L=(M/60)*360
S-L

Lens=A**2+B**2-2*A*B*math.cos((S-L)*math.pi/180)
print(Lens**(1/2))

Solution (Python):
import math

a,b,h,m=map(int,input().split())
t=360*h+m*6-30*h-m/2
ans2=a**2+b**2-2*a*b*math.cos(math.radians(t))
print(math.sqrt(ans2))

Solution (Python):

import math
a, b, h, m = map(int, input().split())
y = 360 * m / 60
x = 360 * (h * 60 + m) / 720
if x == 0 and y >= 180:
    x = 360
if y == 0 and x >= 180:
    y = 360
ang = max(x, y) - min(x, y)
print(math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * math.cos(math.radians(ang)))))

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

x1 = A*math.cos((3-H)*math.pi/6-M*math.pi/(360))
y1 = A*math.sin((3-H)*math.pi/6-M*math.pi/(360))

x2 = B*math.cos((15-M)*math.pi/30)
y2 = B*math.sin((15-M)*math.pi/30)
print(math.sqrt((x2-x1)**2 + (y2-y1)**2))

Solution (Python):
a, b, h, m = map(int, input().split())
import math
lca = 360 * (h + (m / 60)) /12
lcb = 360 * m / 60
if lca > lcb:
    if lca - lcb < 180:
        ctw = a**2 + b**2 - 2 * a * b * math.cos(math.radians(lca - lcb))
    else:
        lcx = 360 - (lca - lcb)
        ctw = a**2 + b**2 - 2 * a * b * math.cos(math.radians(lcx))
else:
    if lca - lcb < 180:
        ctw = a**2 + b**2 - 2 * a * b * math.cos(math.radians(lcb - lca))
    else:
        lcx = 360 - (lcb - lca)
        ctw = a**2 + b**2 - 2 * a * b * math.cos(math.radians(lcx))
c = math.sqrt(ctw)
print(c)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
Ta=H*60+M
a=0.5*Ta
b=6*M
key=abs(b-a)
if key>180:
  key=360-key
c=math.cos(math.radians(key))
ans=A**2+B**2-2*A*B*c
print(math.sqrt(ans))

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

import math
import numpy as np

hi = (360/12*h) + (360/12/60*m)
mi = 360/60*m
kakudo = 0
if abs(hi-mi) >= 180:
  kakudo = 360 - abs(hi-mi)
else:
  kakudo = abs(hi-mi)

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

Solution (Python):
import math

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

dh = ((((60 * H) + M) / 720) * 360 - 90) * -1
dm = ((6 * M) - 90) * -1
h = math.radians(dh)
m = math.radians(dm)

ans = ((A * math.sin(h) - B * math.sin(m)) ** 2 + (A * math.cos(h) - B * math.cos(m)) ** 2) ** 0.5

print(ans)

Solution (Python):
import math

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

time = 60 * H + M

theta_A = 6*time % 360
theta_B = 0.5 * time
if (360 <= theta_B):
    theta_B -= 360

theta = abs(theta_A - theta_B)
if (theta > 180):
    theta = 360 - theta 

theta_rad = math.radians(theta)

C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta_rad))
print(C)

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

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

a_rad=h*30+0.5*m
b_rad=m*6


ABSS=abs(a_rad-b_rad)
D=math.radians(ABSS)


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

Solution (Python):

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

kakudo = (H * 60.0 + M*1.0)/720 * 360
B_kakudo = M*1.0 / 60 * 360

Ax = A * math.sin(math.radians(kakudo))
Ay = A * math.cos(math.radians(kakudo))






Bx = B * math.sin(math.radians(B_kakudo))
By = B * math.cos(math.radians(B_kakudo))






print(math.sqrt(((Bx- Ax)**2 + (By -Ay)**2)))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
c=360*(H/12+M/720)
d=360*M/60
e = math.cos(math.radians(abs(c-d)))
print(math.sqrt(A**2+B**2-2*A*B*e))

Solution (Python):
a,b,h,m=map(int,input().split())
import math
pi=math.pi
s1=30*h+m/2
s2=6*m
s1s2=abs(s2-s1)
cos=math.cos(math.radians(s1s2))
print((a**2+b**2-2*a*b*cos)**0.5)

Solution (Python):
import math

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

ar = (h + m/60)/12 * 360
br = m/60 * 360

cc = (a**2 + b**2) - 2*a*b*math.cos(math.radians(abs(ar-br)))

ans = math.sqrt(cc)


print(ans)

Solution (Python):
import math

A,B,H,M=map(int,input().split())
hx = A * math.cos(math.radians(90 - 30 * (H + M/60)))
hy = A * math.sin(math.radians(90 - 30 * (H + M/60)))
mx = B * math.cos(math.radians(90 - 6*M))
my = B * math.sin(math.radians(90 - 6*M))

print(math.sqrt((hx-mx)**2+(hy-my)**2))

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

a_s = (30 * h) + 0.5 * m
b_s = (6 * m)%360

s = max(a_s,b_s) - min(a_s,b_s)

if s == 0:
    print(abs(a-b))
elif s == 180:
    print(a+b)
else:
    a = Decimal(a)
    b = Decimal(b)
    t = Decimal(2)
    ans = Decimal(math.sqrt(a**t + b**t - t*a*b*Decimal(math.cos(math.radians(s)))))
    print(ans)

Solution (Python):
import math
all = input()
A = int(all.split(' ')[0])
B = int(all.split(' ')[1])
H = int(all.split(' ')[2])
M = int(all.split(' ')[3])
delta_ = H/12+(1/12)*(M/60)-M/60
c = (A**2+B**2-2*A*B*math.cos(2*delta_*math.pi))**0.5
print(c)

Solution (Python):
import sys
import math
input = sys.stdin.readline
def main():
    a,b,h,m = map(int, input().split())
    if abs(m/60 - (h/12+m/720)) >= 1/2:
        sita = (1-abs(m/60 - (h/12+m/720))) * 2 * math.pi
        c_si = math.cos(sita)
        ans = math.sqrt(a**2+b**2-2*a*b*c_si)
        print(ans)
    else:
        sita = abs(m/60 - (h/12+m/720)) * 2 * math.pi
        c_si = math.cos(sita)
        ans = math.sqrt(a**2+b**2-2*a*b*c_si)
        print(ans)
        
        
        
        
if __name__ == "__main__":
    main()

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

import math

a = H*360/12+M*(360/12)/60
b = M*360/60

n = math.radians(abs(b-a) if abs(b-a) <=180 else 360-abs(b-a))

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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
l=360/60*m
s=360/12*(h+m/60)
if abs(l-s)>180:
 t=360-abs(l-s)
else:
 t=abs(l-s)
ans=(a**2+b**2-2*a*b*(math.cos(t*(math.pi)/180)))**(1/2)
print(ans)

Solution (Python):
import math

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

kH =(H*30 + M*0.5)
kM =M*6
x=kH-kM

cosx = math.cos(math.radians(x))
print(math.sqrt(A*A+B*B-2*A*B*cosx))

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

t=60*h+m

sd=(0.5*t)%360
ld=(6*t)%360
x=abs(sd-ld)

if x==180:
    print(s+l)
    exit()
elif x==0:
    print(abs(l-s))
    exit()
else:
    x=min(x,360-x)

radx=math.radians(x)
cosx=math.cos(radx)

print((s**2+l**2-2*l*s*cosx)**0.5)

Solution (Python):
import math
 
def main():
  a, b, h, m = map(int,input().split())
  alpha = 30 * (h + (m / 60))
  beta = 6 * m
  theta = abs(alpha - beta)
  theta = math.radians(theta)
  squear =  a ** 2 + b ** 2 - 2 * a * b * math.cos(theta)
  ans = math.sqrt(squear)
  print(ans)
 
 
if __name__ == '__main__':
  main()

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

theta_h = h / 12 * 2 * np.pi + m / 60 * 2 * np.pi /12
theta_m = m / 60 * 2 * np.pi

a_d = a ** 2
b_d = b ** 2

if theta_h < theta_m:
    deg = theta_m - theta_h
else:
    deg = theta_h - theta_m

res = (a_d + b_d - 2 * a * b * np.cos(deg)) ** 0.5

print(res)

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

c1 = ld - sd
ans = A**2 + B**2 - 2*A*B*math.cos(math.radians(c1))

print(f"{math.sqrt(ans):.10f}")

Solution (Python):
a, b, h, m = list(map(int,input().split()))
r = min(abs(h*30+m*0.5-m*6), 360-abs(h*30+m*0.5-m*6))
import math
c = (a**2+b**2-2*a*b*math.cos(math.radians(r)))**0.5
print(c)

Solution (Python):
from sys import stdin
from math import sin,cos,pi
def main():
    
    readline=stdin.readline
    A,B,H,M=map(int,readline().split())

    s=M*pi/30
    t=(H/6)*pi+(M/360)*pi
    x_A=A*sin(t)
    y_A=A*cos(t)

    x_B=B*sin(s)
    y_B=B*cos(s)

    print(((x_A-x_B)**2+(y_A-y_B)**2)**0.5)
    
if __name__=="__main__":
    main()

Solution (Python):
import math

A,B,H,M=(int(x) for x in input().split())
ang = (30*H - 11*M/2)*math.pi/180;
ans = math.sqrt(A*A + B*B - 2*A*B*math.cos(ang));
print(ans)

Solution (Python):
a,b,h,m = map(int,input().split())
from math import sqrt,cos,radians
the = 30*h-6*m+m/2
kaku = max(the,-the)
if kaku > 180:
    kaku = 360-kaku
    c = a*a + b*b - 2*b*a*cos(radians(kaku))
    print(sqrt(c))
elif kaku == 180:
    print(a+b)  
else:
    c = a*a + b*b - 2*b*a*cos(radians(kaku))
    print(sqrt(c))

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

h_r = math.radians((90 - h * 30 - m * 0.5))
m_r = math.radians((90 - m * 6))
h_v = np.array([math.cos(h_r), math.sin(h_r)]) * a
m_v = np.array([math.cos(m_r), math.sin(m_r)]) * b
ans = (a ** 2 + b ** 2 - 2 * np.dot(h_v, m_v))**(0.5)
print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
j=m*6
h=h*30+m/2
g=abs(j-h)
g=math.radians(g)
x=math.sqrt(abs(a**2+b**2-2*a*b*math.cos(g)))
print(abs(x))

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((30*H+0.5*M)-6*M)))
print(ans)

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


a = (H * 30) + (M * 0.5)
b = M * 6
c = math.radians(abs(a-b))

C = (A**2 + B**2 - 2*A*B*math.cos(c))**0.5

print(C)

Solution (Python):
import math
a, b, h, m = map(float, input().split())
x, y = 360 / 12 * h + 360 / 12 / 60 * m, 360 / 60 * m
d = max(x, y) - min(x, y)
print('%.25f' % math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(d))))

Solution (Python):
from math import *
def calcAngle(h,m): 
        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 radians(angle)
a,b,h,m=map(int,input().split())
angle = calcAngle(h,m)
l=(b-a*cos(angle))**2
r1=a**2
r2=(a*cos(angle))**2
print('{0:.{1}f}'.format(sqrt(l+r1-r2),20))

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

if m == 0:
    k1 = 360
    k2 = h * 30
else:
    k1 = m/5 * 30
    k2 = h * 30 + 30 * k1 / 360

if k1 > k2:
    kaku = k1 - k2
else:
    kaku = k2 - k1

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

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")


def solve():
    a, b, h, m = LI()
    d = h * 30 - m * 5.5
    if d > 180:
        d = 360 - d
    print(sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(2 * d * math.pi / 360)))
    return



if __name__ == '__main__':
    solve()

Solution (Python):
import math

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

t = h*60 + m
angle = abs(t*0.5 - t*6)
if angle != 0:
    angle %= 360

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

Solution (Python):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,b,h,m=map(int,input().split())
hun=360*m/60
ji=360*(h*60+m)/720
sita=abs(hun-ji)




if sita==180:
    print(a+b)
    quit()
if sita==0:
    print(abs(a-b))
    quit()

if sita>180:
    sita=360-sita

hen1=b*math.cos(math.radians(180-sita))+a
hen2=b*math.sin(math.radians(sita))
print(((hen1)**2+(hen2)**2)**0.5)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
time = H*60+M
h_a = (time/720)*360
m_a = M*6
arg = abs(h_a - m_a)
print(math.sqrt(float(A)**2 + float(B)**2 - 2*A*B*math.cos(math.radians(arg))))

Solution (Python):
import numpy as np
A, B, H, M = map(int,input().split())
a_rad = H*np.pi/6 + M*np.pi/360
b_rad = M*np.pi/30
two_vec = np.array([[A, a_rad], [B, b_rad]])
def polar2cartesian(position):
    num = position.shape[0]
    newPosition = np.empty([num,2], dtype=np.float64)
    newPosition[:,0] = position[:,0] * np.cos(position[:,1])
    newPosition[:,1] = position[:,0] * np.sin(position[:,1])
    return newPosition
ans = polar2cartesian(two_vec)
print(np.linalg.norm(ans[0]-ans[1]))

Solution (Python):
import math

def main():
    a,b,h,m = map(int,input().split())
    fun = h*60 + m
    angleM = (fun * 6) % 360
    angleH = (fun * 0.5) % 360

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



if __name__ == "__main__":
    main()

Solution (Python):
import math
A,B,H,M=map(int, input().split())
zikan=0
hun=0
zikan=(M*0.5)+(30*H)
hun=M*6
hari=abs(zikan-hun)
if hari>180:
    hari=360-hari
ans=0
ans_kari=0
ans_kari=A**2+B**2-2*A*B*math.cos(math.radians(hari))
ans=math.sqrt(ans_kari)
print(ans)

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

long=math.pi*h/6 + (math.pi/6)*m/60
short=math.pi*m/30

dg=abs(long-short)

ans=(a**2 +b**2 -2*a*b*math.cos(dg))**0.5
print(ans)

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


omega = H*60+M
tanshin = omega*0.5
choshin = omega*6 % 360



shita = max(tanshin,choshin)-min(tanshin,choshin)
if shita > 180:
    shita = 360 - shita


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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
kakudo_b = float(m * 6)
kakudo_a = float(h * 30 + m / 2)

if kakudo_a > kakudo_b and kakudo_a - kakudo_b < 180:
    kakudo_kyori = kakudo_a - kakudo_b
elif kakudo_a > kakudo_b and kakudo_a - kakudo_b > 180:
    kakudo_kyori = kakudo_b + (360 - kakudo_a)
elif kakudo_a == kakudo_b:
    kakudo_kyori = 0
elif kakudo_b > kakudo_a and kakudo_b - kakudo_a < 180:
    kakudo_kyori = kakudo_b - kakudo_a
elif kakudo_b > kakudo_a and kakudo_b - kakudo_a > 180:
    kakudo_kyori = kakudo_a -kakudo_b
else:
    kakudo_kyori = 180

if kakudo_kyori == 0:
    if a > b:
        ans = a-b
        print('{:.20f}'.format(ans))
    elif a==b:
        ans = 0
        print('{:.20f}'.format(ans))
    else:
        ans = b-a
        print('{:.20f}'.format(ans))
elif kakudo_kyori == 180:
    ans = a + b
    print('{:.20f}'.format(ans))
else:
    cos = math.cos(math.radians(kakudo_kyori))
    ans_2 = a * a + b * b - 2 * a*b*cos
    ans = ans_2 ** 0.5
    print('{:.20f}'.format(ans))

Solution (Python):
import math

def main():
    A,B,H,M=map(int,input().strip().split())
    round_hour=12*60
    round_min=60
    
    
    degree_hour=(60*H+M)/round_hour*360
    degree_min=M/round_min*360
    radian_hour=math.radians(degree_hour)
    radian_min=math.radians(degree_min)
    
    
    d1=A*math.cos(radian_hour)-B*math.cos(radian_min)
    d2=A*math.sin(radian_hour)-B*math.sin(radian_min)
    
    return math.sqrt(d1**2+d2**2)

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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
kaku=abs((h*30+m*0.5)-(m*6))
distance=(a**2+b**2-2*a*b*math.cos(math.radians(kaku)))**(1/2)
print(format(distance, '.20f'))

Solution (Python):
import math

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


def choshin_angle(m):
    return 6 * m

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

theta = abs(tanshin_angle(h, m) - choshin_angle(m))

if (theta >= 180.):
    theta = 360 - theta

theta = math.radians(theta)

x2 = a**2 + b**2 - 2 * a * b * math.cos(theta)

x = math.sqrt(x2)

print(x)

Solution (Python):

import math
 
abhm = list(map(int,input().split()))
A, B, H, M = abhm[0], abhm[1], abhm[2], abhm[3]





theta_A = H*30 + M*0.5
theta_B = M*6



if (  abs( theta_A - theta_B ) <= 180 ):
  theta = abs( theta_A - theta_B )
  
else:
  theta = 360 - abs( theta_A - theta_B )




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

print(C)

Solution (Python):
import math
abhm = list(map(int, input().split()))

Htheta=360/720*(abhm[2]*60+abhm[3])
Mtheta=360/60*(abhm[3])

if abs(Htheta-Mtheta)>180:
    angle=360-abs(Htheta-Mtheta)
else:
    angle=abs(Htheta-Mtheta)

print(math.sqrt(abhm[0]**2+abhm[1]**2-2*abhm[0]*abhm[1]*math.cos(angle*math.pi/180)))

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

r = 0
rm = 6*m
rh = 30*h + m/2

if abs(rm-rh) < 180:
  r = abs(rm-rh)
else:
  r = 360 - abs(rm-rh)

if r==180:
  print(format(a+b, '.25f'))
else:
  print(format((math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(r)))),'.25f'))

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

d = 5.5 * (60*H+M)
distan = d - 360 * (d // 360)

if distan>180:
    distan=360-distan

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

Cpow2 = pow(A,2)+pow(B,2)- 2* A * B * cosC

print(Cpow2**(0.5))

Solution (Python):
import math

def yogen(a, b, angle):
    return math.sqrt(a*a+b*b-2.0*a*b*math.cos(math.pi * angle/180.0))

d = [float(i) for i in input().split()]

h_angle = 360.0/12.0 * d[2] + 360.0/12.0/60.0*d[3]
m_angle = 360.0/60.0 * d[3]
diff_angle = min(math.fabs(h_angle-m_angle), 360.0-math.fabs(h_angle-m_angle))

print(yogen(d[0], d[1], diff_angle))

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

def solve(A, B, H, M):
    Hr = (H * 60 + M) * 0.5
    Mr = M * 6
    r = abs(Hr - Mr)
    if r > 180:
        r = 360 - r

    if r == 90:
        print(sqrt(A ** 2 + B ** 2))
    else:
        print(sqrt(A ** 2 + B ** 2 - (2 * A * B * cos(radians(r)))))

A, B, H, M = map(int, open(0).read().split())
solve(A, B, H, M)

Solution (Python):
import math

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

def hour_to_rad(hour):
    return hour * (math.pi * 2 / 12)

def mod_hour_to_rad(minute):
    return minute * (math.pi * 2 / (12 * 60))

def minute_to_rad(minute):
    return minute * (math.pi * 2 / 60)

def calc_cosine_edge(a, b, angle):
    return abs(a * a + b * b - 2 * a * b * math.cos(angle)) ** 0.5

angle = abs(hour_to_rad(h) + mod_hour_to_rad(m) - minute_to_rad(m))

print(calc_cosine_edge(a, b, angle))

Solution (Python):
import math

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

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

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

Solution (Python):
import math

A,B,H,M=map(int,input().split())
th=abs((2*math.pi*M/60)-((2*math.pi*H/12) + (M/60)*2*math.pi/12))
ans=math.sqrt(A**2 + B**2 -2*A*B*math.cos(th))
print(ans)

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

a,b,h,m = map(int,input().split())
d1 = h*30 + m*0.5
d2 = m*6
kakudo = abs(d2-d1)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo)))
print(ans)