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())

arad = (30 * h) + 0.5 * m
brad = 6 * m
rad1 = abs(arad - brad)
if rad1 > 180:
    rad1 = 360 - rad1

cos = math.cos(math.radians(rad1))

ans = a**2 + b**2 - 2*a*b*cos

print(ans**0.5)

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

Solution (Python):
import math

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


kaku_a = (360 * h / 12) + (m / 2)




kaku_b = 360 * m / 60



if kaku_a > kaku_b:
    kaku = kaku_a - kaku_b
else:
    kaku = kaku_b - kaku_a


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

print(lengs)

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

start = 30*H
start -= 5.5*M
if start >=180:
  start = 360-start

syahen = A**2 + B**2 - 2*A*B*math.cos(math.radians(start))
print(math.sqrt(syahen))

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

hpm = 0.5
mpm = 6

dif = abs(mpm * m - hpm * h * 60 - hpm * m)
if dif == 360.0:
    dif = 0.0
nagasa_beki = a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(dif)))
kyori = math.sqrt(nagasa_beki)

print(kyori)

Solution (Python):
import math

text = input()
a_str, b_str, h_str, m_str = text.split()
a = int(a_str)
b = int(b_str)
h = int(h_str)
m = int(m_str)
h_x = math.sin((h + m / 60) / 12 * 2 * math.pi)*a
h_y = math.cos((h + m / 60) / 12 * 2 * math.pi)*a
m_x = math.sin(m / 60 * 2 * math.pi)*b
m_y = math.cos(m / 60 * 2 * math.pi)*b
z = math.sqrt(pow(h_x - m_x, 2) + pow(h_y - m_y, 2))
print(z)

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

a_theta = 30*H+0.5*M
a_sin_theta = math.sin(math.radians(a_theta))
a_cos_theta = math.cos(math.radians(a_theta))

b_theta = 6*M
b_sin_theta = math.sin(math.radians(b_theta))
b_cos_theta = math.cos(math.radians(b_theta))

ax = A*a_cos_theta
ay = A*a_sin_theta

bx = B*b_cos_theta
by = B*b_sin_theta

distance = math.sqrt((ax-bx)**2+(ay-by)**2)
print(distance)

Solution (Python):
a,b,h,m = map(int,input().split())
import math
alp = 0.5*(h*60+m)/180*math.pi
be = 6*m/180*math.pi
if abs(alp-be) <= math.pi:
    s = abs(alp-be)
else:
    s = 2*math.pi - abs(alp-be)
l = (a**2+b**2 - 2*a*b*math.cos(s))**(1/2)
print(l)

Solution (Python):
import math
num = input()

num_list = num.split()
min_time = int(num_list[2]) * 60 + int(num_list[3])
hour_arg = min_time * 0.5
min_arg = int(num_list[3]) * 6

arg = abs(hour_arg - min_arg)
if arg == 0:
  answer = 0
if arg > 180:
  arg = 360 - arg
answer = pow(int(num_list[0]), 2) + pow(int(num_list[1]), 2) - (int(num_list[0]) * int(num_list[1]) * 2 * math.cos(math.radians(arg)))

print("{}".format(math.sqrt(answer)))

Solution (Python):
import numpy as np


def main():
    a, b, h, m = map(int, input().split())
    short_needle = np.array([a*np.cos(np.radians(-h*30-30*((m*6)/360)+90)), a*np.sin(np.radians(-h*30-30*((m*6)/360)+90))])
    long_needle = np.array([b*np.cos(np.radians(-m*6+90)), b*np.sin(np.radians(-m*6+90))])
    ans = np.linalg.norm(short_needle - long_needle)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math

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

da=180*(h+m/60)/6
db=180*m/30
d=da-db

if da>=db:
  if d>=180:
    d=360-d
else:
  if -d>=180:
    d=360+d
  else:
    d=-d

d=math.pi*d/180
cos=math.cos(d)
answer2=a**2+b**2-2*a*b*cos

print(answer2**(1/2))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
tansin = h * 30 + m * 0.5

tyousin = m * 6

if tansin > 360:
    tansin = tansin - 360
if tyousin > 360:
    tyousin = tyousin - 360


rad = math.radians(abs(tansin - tyousin))
c = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(math.sqrt(c))

Solution (Python):

import numpy as np
a, b, h, m  = map(float, input().split())
m_ = (np.pi * m/ 30) 
h_ = (np.pi * h/ 6)  + (np.pi * m/360)


r = ((a * np.cos(h_) - b * np.cos(m_)) ** 2
     + (a * np.sin(h_) - b * np.sin(m_)) ** 2)** 0.5

print(r)

Solution (Python):
from math import *
a, b, h, m = map(int, input().split())
s = 30*(h+m/60)
l = 6*m
t = abs(s-l)
pi = acos(-1)
ans = a**2+ b**2 - 2*a*b*cos(t*pi/180)
print(sqrt(ans))

Solution (Python):
import math

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

MIN = H*30 + M*(1/2) - 6*M

C = A**2 + B**2 - 2*A*B*round(math.cos(math.radians(MIN)),15)

print('{:.18f}'.format(C**0.5))

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

h = h * 60 + m

h_angle = h / 2
m_angle = m * 6
C = abs(h_angle - m_angle)
if C > 180 :
  C = 360 - C

import math
x = a**2 + b**2 - 2*a*b*math.cos(math.radians(C))
print(x**(1/2))

Solution (Python):
import math

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

H_L = 0.5 * (H * 60 + M)
M_L = 6 * M

R = math.cos(math.radians(abs(H_L - M_L)))

X = A ** 2 + B ** 2 - 2 * A * B * R
Y = math.sqrt(X)

print(Y)

Solution (Python):
import numpy as np
a, b, h, m = map(int, input().split())
ang = abs((30 * h + .5 * m) % 360 - (6 * m) % 360)
ang *= np.pi / 180
print(np.sqrt(a**2 + b**2 - 2 * a * b * np.cos(ang)))

Solution (Python):



"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""


"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""

import math
A,B,H,M= map(int,input().split())
if abs(30*H-5.5*M)%360<=180:
    i = abs(30*H-5.5*M)%360
else:
    i = 360-abs(30*H-5.5*M)%360


sin30 = math.cos(math.radians(i))

ans = (A*A+B*B-2*A*B*sin30)
print(math.sqrt(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=calcAngle(h,m)
rad=math.radians(angle)
val=math.cos(rad)
c=math.sqrt(pow(a,2)+pow(b,2)-2*a*b*val)
print(c)

Solution (Python):
import math


def inlt():
    return(list(map(int, input().split())))


a, b, h, m = inlt()

theta = abs(.5 * (60 * h + m) - 6*m)
if theta > 180:
    theta = 360 - theta



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

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

rad = math.radians(arg3)

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

Solution (Python):
import math
x=[int(i) for i in input().split()]
a=x[0]
b=x[1]
h=x[2]
m=x[3]
db=(m/60)*360
da=(h/12)*360+(m/60)*30
if(da==db):
    print(abs(a-b))
elif(da>db):
    f=a**2
    f+=(b**2)
    diff=da-db
    if(diff>180):
        diff=360-diff
    f-=(2*a*b*math.cos(math.radians(diff)))
    print(math.sqrt(f))
elif(db>da):
    f=a**2
    f+=(b**2)
    diff=db-da
    if(diff>180):
        diff=360-diff
    f-=(2*a*b*math.cos(math.radians(diff)))
    print(math.sqrt(f))

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

import math
deg_a = (360.0/12.0)*h+(360.0/12.0)*(m/60)
deg_b = (360.0/60.0)*m
deg = abs(deg_a-deg_b)

d = math.sqrt((math.sin(math.radians(deg))*a)**2+(b-a*math.cos(math.radians(deg)))**2)
print('{:.11g}'.format(d))

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

hs = 90 - (H * 30) - (30 * M / 60)
ms = 90 - M * 6

hs = math.pi * hs / 180
ms = math.pi * ms / 180

ax = A * math.cos(hs)
ay = A * math.sin(hs)

bx = B * math.cos(ms)
by = B * math.sin(ms)

dis = math.sqrt(pow(ax - bx, 2) + pow(ay - by, 2))
print(dis)

Solution (Python):
import sys
import math
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B, H, M = map(int, input().split())
    hm = abs(H * 30 + H * (M / 360) - M)
    hm = abs(H * 30 + 0.5 * M - M * 6)
    if hm > 180:
        hm = 360 - hm
    cos_v = math.cos(math.radians(hm))
    print((A ** 2 + B ** 2 - 2 * A * B * cos_v) ** 0.5)

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

arg = abs(30*h - 5.5*m)

if arg == 180:
    print(b+a)
    exit()

if arg == 0:
    print(abs(b-a))
    exit()

if arg > 180:
    arg = 360 - arg

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

print(length)

Solution (Python):
import math

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

a_kakudo = ((h*60+m)*0.5)
b_kakudo = m * 6

if a_kakudo == b_kakudo:
    print(max(a,b)-min(a,b))
elif a_kakudo + b_kakudo == 180 or a_kakudo + b_kakudo == 360:
    print(a + b)
elif max(a_kakudo,b_kakudo)- min(a_kakudo, b_kakudo) == 90 or max(a_kakudo,b_kakudo)- min(a_kakudo, b_kakudo) == 270:
    print(math.sqrt(a**2 + b**2))
else:
    print(math.sqrt(a**2+b**2-((2*a*b*math.cos(math.radians(max(a_kakudo,b_kakudo)- min(a_kakudo, b_kakudo)))))))

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

rad = min(abs(6*m - 30*h - 0.5*m), 360-abs(6*m -30*h - 0.5*m))

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


ans = (a*a + b*b - 2*a*b*cosc) ** 0.5
print(ans)

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

tanshin = ((h * 60 + m) * 360 / (12 * 60))
choshin =  (m * 360 / 60) 
bcos = tanshin - choshin


c2 = (a ** 2) + (b ** 2) - (2 * a * b * math.cos(math.radians(bcos)))

print(math.sqrt(c2))

Solution (Python):
import math
a, b , h, m = map(int, input().split())
xa = a * math.sin((h+(m/60))/6*math.pi)
ya = a * math.cos((h+(m/60))/6*math.pi)
xb = b * math.sin(m/30*math.pi)
yb = b * math.cos(m/30*math.pi)
print(math.sqrt((xa-xb)**2 + (ya-yb)**2))

Solution (Python):
import math
l1 , l2 ,hour, minute  = map(int,input().split())

minuteAngel = (float(minute)*360)/60
hourAngel = (float(hour)%12)*30 + (float(minute)*30)/60
angel = abs(hourAngel - minuteAngel)

tmp = l1**2 + l2**2 - 2 * l1 * l2 * math.cos(math.radians(angel))

print(math.sqrt(tmp))

Solution (Python):
import math
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, H, M = map(int, input().split())

    h = H * 30 + M * 0.5
    m = M * 6
    rad = math.radians(abs(h - m))
    x = A * A + B * B - 2 * A * B * math.cos(rad)
    print(x ** 0.5)


main()

Solution (Python):
import math
A,B,H,W=map(int,input().split())
wa=360/12

Q=abs(wa*H-5.5*W)
ans=(A**2)+(B**2)-(2*A*B*math.cos(math.radians(Q)))
print(ans**(1/2))

Solution (Python):
import math

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


s = 30* h + m / 2

l = 6* m



if s >= l:
  g = s - l

else:
  g = l - s

ga = min(g, (360 - g))

cos = math.cos(math.radians(ga))


ans = a**2 + b**2 - 2* a* b* cos

final = math.sqrt(ans)

print(final)

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


deg_h = 0.5 * (60 * H + M)
deg_m = 6 * M
rad_h = math.radians(deg_h)
rad_m = math.radians(deg_m)

theta = abs(rad_h - rad_m)
c2 = (A ** 2) + (B ** 2) - (2 * A * B * math.cos(theta))
print(math.sqrt(c2))

Solution (Python):
import math
import numpy as np
a,b,h,m=map(int,input().split())
hun=60*h+m
k=5.5*(60*h+m)
if k>180:
    k=360-k
ansa=(a**2+b**2-2*a*b*math.cos(math.radians(k)))
ans=math.sqrt(ansa)
print(ans)

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

rad = min(abs(6*m - 30*h - 0.5*m), 360-abs(6*m -30*h - 0.5*m))

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


ans = (a*a + b*b - 2*a*b*cosc) ** 0.5
print(ans)

Solution (Python):
from sys import stdin
import math

A, B, H, M = [int(x) for x in stdin.readline().rstrip().split()]

H %= 12

short = M*6
long = (H*60+M)/2.0

dif = abs(short-long)
angle = min(dif, 360 - dif)

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

print(length)

Solution (Python):

import math

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

h_a=h%12
k_a = (h_a*60+m)*0.5

k_b = m*6


if k_a<=90:
    
    a_x = a*math.cos(math.radians(90-k_a))
    a_y = a*math.sin(math.radians(90-k_a))
elif k_a<=180:
    
    a_x = a*math.cos(math.radians(k_a-90))
    a_y = -a*math.sin(math.radians(k_a-90))
elif k_a<=270:
    
    a_x = -a*math.cos(math.radians(270-k_a))
    a_y = -a*math.sin(math.radians(270-k_a))
else:
    
    a_x = -a*math.cos(math.radians(k_a-270))
    a_y = a*math.sin(math.radians(k_a-270))
    
if k_b<=90:
    
    b_x = b*math.cos(math.radians(90-k_b))
    b_y = b*math.sin(math.radians(90-k_b))
elif k_b<=180:
    
    b_x = b*math.cos(math.radians(k_b-90))
    b_y = -b*math.sin(math.radians(k_b-90))
elif k_b<=270:
   
    b_x = -b*math.cos(math.radians(270-k_b))
    b_y = -b*math.sin(math.radians(270-k_b))
else:
    
    b_x = -b*math.cos(math.radians(k_b-270))
    b_y = b*math.sin(math.radians(k_b-270))


print('{:.10g}'.format(math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2)))

Solution (Python):
import numpy as np
A, B, H, M = map(int, input().split())
aH = H / 12.0 * 2 * np.pi + M / (12 * 60) * 2 * np.pi
aM = M / 60.0 * 2 * np.pi
print(np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(np.abs(aH - aM))))

Solution (Python):
import math

a=input()
a=a.split()
l1=int(a[0])
l2=int(a[1])
h=int(a[2])
m=int(a[3])

de1=math.radians(360*h/12+0.5*m)
de2=math.radians(360*m/60)



x1=l1*math.cos(de1)
y1=l1*math.sin(de1)



x2=l2*math.cos(de2)
y2=l2*math.sin(de2)



l_2=pow(x1-x2,2)+pow(y1-y2,2)
l=pow(l_2,0.5)

print(l)

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

rad1 = math.pi*2*(h/12 + m/720 - m/60)
rad2 = math.pi*2*(1-h/12 - m/720 + m/60)
kaku = min(abs((30*h+0.5*m)-60*m), abs(360-(30*h+0.5*m)+60*m))
if kaku == 180:
    print(a+b)
elif kaku == 0:
    print(abs(a-b))
else:
    rad = min(rad1, rad2)
    print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad)))

Solution (Python):
import numpy as np

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

if H > 12:
    H -= 12

v = (H + (M / 60) * (1 / 12))
ji_ang = (H / 12 +((M / 60) * (1 / 12))) * 2 * np.pi

if 0 <= v <= 3:
    ji_ang = (np.pi / 2) - ji_ang
elif 3 < v <= 6:
    ji_ang = (ji_ang - (np.pi / 2)) * -1
elif 6 < v <= 9:
    ji_ang = (ji_ang - np.pi) * -1 - np.pi / 2
else:
    ji_ang = np.pi - (ji_ang - (np.pi * (3 / 2)))

ji_x = A * np.cos(ji_ang)
ji_y = A * np.sin(ji_ang)

fun_ang = (M / 60) * 2 * np.pi

if 0 <= M <= 15:
    fun_ang = (np.pi / 2) - fun_ang
elif 15 < M <= 30:
    fun_ang = (fun_ang - (np.pi / 2)) * -1
elif 30 < M <= 45:
    fun_ang = (fun_ang - np.pi) * -1 - np.pi / 2
else:
    fun_ang = np.pi - (fun_ang - (np.pi * (3 / 2)))

fun_x = B * np.cos(fun_ang)
fun_y = B * np.sin(fun_ang)

x = (ji_x - fun_x)
y = (ji_y - fun_y)

print(np.sqrt(x ** 2 + y ** 2))

Solution (Python):
import math
t = input().split()
t = [int(i) for i in t]
r = math.sqrt(t[0]*t[0]+ t[1]*t[1])
h = t[2]
m = t[3]
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)
print(math.sqrt(r*r - 2*t[0]*t[1]*math.cos(angle*(2*math.pi/360))))

Solution (Python):
import math
import numpy as np
A, B, H, M = (int(i) for i in input().split())  

angleA = math.pi * 2 * (1 - (H/12 + 1/12 * M/60) + 1/4)
angleB = math.pi * 2 * (1 - M/60 + 1/4)

a = np.array([A * math.cos(angleA), A * math.sin(angleA)])
b = np.array([B * math.cos(angleB), B * math.sin(angleB)])

print(np.linalg.norm(a - b))

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

import math

degreeA = float((H * 60 + M) / 2)
degreeB = float(M * 6)

degreeAB = abs(degreeA - degreeB)

if degreeAB > 180:
    degreeAB = 360 - degreeAB
C = float(A ** 2 + B ** 2 - 2 * A * B * float(math.cos(float(degreeAB * math.pi / 180))))
print(math.sqrt(C))

Solution (Python):
import math

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

m_abs_deg = 6.0 * m
h_abs_deg = 0.5 * m + 30.0 * h
rel_deg = math.fabs(m_abs_deg - h_abs_deg)
if rel_deg > 180.0:
    rel_deg = 360.0 - rel_deg

cos_c = math.cos(math.radians(rel_deg))
c_sq = a * a + b * b - 2.0 * a * b * cos_c
c = math.sqrt(c_sq)

print(c)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
long_ = [0, 0]
short_ = [0, 0]


rad_a = 90 - ( 360 * H/12 + 30 * M/60)
rad_b = 90 - ( 360 * M/60)




long_[0] = A * math.cos(math.radians(rad_a))
long_[1] = A * math.sin(math.radians(rad_a))
short_[0] = B * math.cos(math.radians(rad_b))
short_[1] = B * math.sin(math.radians(rad_b))




ans = math.sqrt((long_[0]-short_[0])**2 + (long_[1]-short_[1])**2)
print(ans)

Solution (Python):
import math

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

rShort = H*30+M*0.5
rLong = M*6


ang=abs(rLong-rShort)



ang=min(ang,abs(360-ang))


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

print(math.sqrt(ans))

Solution (Python):
a,b,h,m = map(int,input().split())
import math
ar = math.pi * 2 * (h * 60 + m) / 720 
br = math.pi * 2 * m / 60 
r = abs(ar-br)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r))
print(ans)

Solution (Python):
import math

a,b,h,m = map(int,input().split())
mr = m*6
hr = ((h*60+m)*360)/720

rad = hr- mr
t = math.cos(math.radians(rad))
ans = a**2+b**2-(2*a*b*t)

print(math.sqrt(ans))

Solution (Python):
import math

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

th1 = (H + M/60)*math.pi/6
th2 = M*math.pi/30

RS2 = (B*math.sin(th2) - A*math.sin(th1))**2
RC2 = (B*math.cos(th2) - A*math.cos(th1))**2
R2 = RS2 + RC2
print(R2**(1/2))

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

p = M*2*math.pi/60
q = H/12*2*math.pi + p/12
Mx = B*math.sin(p)
My = B*math.cos(p)
Hx = A*math.sin(q)
Hy = A*math.cos(q)
L = math.sqrt((Mx-Hx)**2 + (My-Hy)**2)
print(L)

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

import math

sita = min(abs(30*H-11*M/2), 360-abs(30*H-11*M/2))





print((A**2 + B**2 - 2*A*B*math.cos(math.radians(sita)))**(1/2))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
a_deg=h*30+m*0.5
b_deg=m*6
deg=math.radians(abs(b_deg-a_deg))
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())
rad=abs(math.radians(30*(h+m/60)-6*m))


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

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

d = (l*30+o*0.5)-(o*6)
a = (n**2+m**2)-(2*n*m)*(math.cos(math.radians(d)))

print(math.sqrt(a))

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

largeD = 30
smallD = 6

if H == 6 and M == 0:
    num = A + B
    print('{:.10f}'.format(num))
    exit()
else:
    D = H * largeD
    d = M * smallD
    
    D += 0.5 * M
    if (D >= d):
        num = (A ** 2 + B**2) - (2 * A * B * math.cos(math.radians(D - d)))
        print('{:.10f}'.format(math.sqrt(num)))
    elif (D < d):
        num = (A ** 2 + B**2) - (2 * A * B * math.cos(math.radians(d - D)))
        print('{:.10f}'.format(math.sqrt(num)))

Solution (Python):
import math as m
A,B,H,M=map(int,input().split())
a=(30*H)+(M/2)
b=M*6
if b-a==180 or a-b==180:
    print(A+B)
else:
    if b-a>=0:
        if b-a<180:
            c=b-a
            d=m.radians(c)
            f=m.cos(d)
            e=A*A+B*B-2*A*B*f
            g=m.sqrt(e)
            print(g)
        else:
            c=360-(b-a)
            d=m.radians(c)
            f=m.cos(d)
            e=A*A+B*B-2*A*B*f
            g=m.sqrt(e)
            print(g)
    else:
        if a-b<180:
            c=a-b
            d=m.radians(c)
            f=m.cos(d)
            e=A*A+B*B-2*A*B*f
            g=m.sqrt(e)
            print(g)
        else:
            c=360-(a-b)
            d=m.radians(c)
            f=m.cos(d)
            e=A*A+B*B-2*A*B*f
            g=m.sqrt(e)
            print(g)

Solution (Python):
import math

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

m_deg = float((m/60) * 360)
h_deg = float(((h*60 +m) / (12*60) ) * 360)  


diff=m_deg-h_deg

if abs(diff)>=180:
    diff=float(360-abs(diff))

cos=math.cos(math.radians(diff))



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

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

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


p = 2*math.pi*(h*60+m)/720
x,y = a*math.cos(p),a*math.sin(p)

q = 2*math.pi*m/60
z,w = b*math.cos(q),b*math.sin(q)


print(((x-z)**2 + (y-w)**2)**0.5)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
if(h==0 and m==0):
  print(abs(a-b))
else:  
  ah=(h*30)+(m*0.5)
  am=m*6
  an=abs(ah-am)
  f=abs(360-an)
  ang=min(an,f)
  d=math.cos(math.radians(ang))
  z=math.sqrt((a**2)+(b**2)-(2*b*a*d))
  print(z)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h=h*30+(m/60)*30
m=m*6
diff=abs(h-m)*((math.pi)/180)
if(diff>180):
    diff=diff-180
ans=a*a+b*b-2*a*b*(math.cos(diff))
print(math.sqrt(ans))

Solution (Python):

import math
import sys
input = sys.stdin.readline
A,B,H,M = (int(x) for x in input().split())

min_deg =math.radians(360//60*M)
min_x =B *math.sin(min_deg)
min_y =B *math.cos(min_deg)


hor_deg =math.radians(360//12*(H +M/60))
hor_x =A *math.sin(hor_deg)
hor_y =A *math.cos(hor_deg)
xx =min_x -hor_x
yy =min_y -hor_y
distance =math.sqrt(xx**2 + yy**2)
print(distance)

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


h_x = a*math.cos(math.radians(90-(h*60+m)/2))
h_y = a*math.sin(math.radians(90-(h*60+m)/2))


t_x = b*math.cos(math.radians(90-(m*6)))
t_y = b*math.sin(math.radians(90-(m*6)))



print((abs(h_x-t_x)**2+abs(h_y-t_y)**2)**0.5)

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

Solution (Python):
import math

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

radH = 360 * H / 12 + 30 * M / 60
radM = 360 * M / 60 

if radH > radM:
  rad = radH - radM
else:
  rad = radM - radH


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

S = A*A + B*B - 2*A*B*cosC

print(math.sqrt(S))

Solution (Python):
import math

A, B, H, M = map(int, input().split())
theta = abs(0.5*(60*H+M)-6*M)
if theta == 0:
    print(abs(A-B))
elif theta < 180:
    C = A**2+B**2-2*A*B*math.cos(theta*math.pi/180)
    print(math.sqrt(C))
elif theta == 180:
    print(A+B)
else:
    theta = 360-theta
    C = A**2+B**2-2*A*B*math.cos(theta*math.pi/180)
    print(math.sqrt(C))

Solution (Python):
import math
a,b,h,m = map(int, input().split())
if abs(30*h-5.5*m)%360<=180:
    t = abs(30*h-5.5*m)%360
    cost = math.cos(math.radians(t))
    r = a*a + b*b - 2*a*b*cost
    print(math.sqrt(r))
else:
    t = 360-abs(30*h-5.5*m)%360
    cost = math.cos(math.radians(t))
    r = a*a + b*b - 2*a*b*cost
    print(math.sqrt(r))

Solution (Python):
import math
def cal_cos(n): 
  
    degree = math.radians(n)
    cosx = math.cos(degree)
  
    return cosx 
  

def third_side(a, b, c): 
    angle = cal_cos(c) 
    return math.sqrt((a * a) + 
                   (b * b) - 2 * a * b * angle) 
                   

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 
    
l = list(map(int,input().split()))

angle = calcAngle(l[2],l[3])
distance = third_side(l[0],l[1],angle)

print ('%.10f'%distance)

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

Solution (Python):
import math
a,b,h,m = map(int,input().split())
short = h*30+m/2
long = m*6
ang = abs(short-long)
ang = ang if ang <= 180 else 360-ang
hen = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(ang)))
print(hen)

Solution (Python):
import math
def resolve():
    A,B,H,M=map(int, input().split()) 
    Arad = (M%60)*6
    Brad = (H%12)*30+(M/60)*30
    c2 = A**2+B**2-2*A*B*math.cos(math.radians(Arad-Brad))
    c = math.sqrt(c2)
    print(c)
resolve()

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

import math

dig = min(abs((H * 60 + M) * 0.5 - M*6), 360 - abs((H * 60 + M) * 0.5 - M*6))
if dig <= 90:
    a2 = A * math.cos((dig/180) * math.pi)
    a3 = A * math.sin((dig/180) * math.pi)
    print(((B-a2)**2 + a3**2)**(1/2))

elif dig > 90:
    dig1 = 180 - dig
    a2 = A * math.sin((dig1/180) * math.pi)
    a3 = A * math.cos((dig1/180) * math.pi)
    print(((B+a3)**2 + a2**2)**(1/2))

Solution (Python):
import numpy as np
import math

A, B, H, M = map(int, input().split())
deg = 360 * (11*M - 60*H)/720
c = np.cos(math.radians(deg))
ans = math.sqrt(A**2 + B**2 -2*A*B*c)
print(ans)

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

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

import math

if H == 12:
    H = 0

a_rad = 2 * math.pi * (H / 12 + M / 720)
b_rad = 2 * math.pi * (M /60)

ab_rad = a_rad - b_rad
ba_rad = b_rad - a_rad

if ab_rad == math.pi:
    d = A + B
if ab_rad == 0:
    d = B - A
if 0 < ab_rad < math.pi:
    d = math.sqrt(A**2 + B **2 - 2*A*B*math.cos(ab_rad))
else:
    d = math.sqrt(A**2 + B **2 - 2*A*B*math.cos(ba_rad))
print(d)

Solution (Python):
import sys
import math
import itertools

a, b, h, m = map(int, input().split())
ans = 0
hour = (h/12)*360+(m/60)*30
minutes = (m / 60)*360
deg = max(hour,minutes)-min(hour,minutes)
if (deg > 180):
    deg = 360 - deg
print(math.sqrt(a ** 2 + b ** 2 - (2 * a * b * math.cos(math.radians(deg)))))

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

Solution (Python):
import math
num = list(map(int, input().split()))
hour_len   = num[0]
minute_len = num[1]
hour       = num[2]
minute     = num[3]

hour_degree = (hour*60 + minute)*0.5
minute_degree = minute*6

diff_degree = abs(hour_degree - minute_degree)
if(abs(hour_degree - minute_degree) > 180):
  diff_degree = 360 - diff_degree

result = pow(hour_len,2)+pow(minute_len,2)-2*hour_len*minute_len*math.cos(math.radians(diff_degree))

print(math.sqrt(result))

Solution (Python):
import itertools
import math
import fractions
import functools
import copy

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

lo = 30*h + 0.5 * m
sh = 6 * m
do = min(lo - sh, 360 - (lo-sh))


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

Solution (Python):
import numpy as np
a, b, h, m = map(float, input().split())
gamma = np.pi * (h/6.0 - 11*m/360.0)
dis = np.sqrt(a**2. + b**2.-2.0 * a*b*np.cos(gamma))
print(dis)

Solution (Python):
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())


import math
def solve(A,B,H,M):
    
    t = 60 * H + M
    
    
    
    alpha = t % (12 * 60)
    alpha /= (12.0 * 60.0)
    alpha = (0.25 - alpha) % 1.00
    
    alpha *= math.pi * 2

    beta = t % (60)
    beta /= (60.0)
    beta = (0.25 - beta) % 1.00
    
    beta *= math.pi * 2

    x1, y1 = A * math.cos(alpha), A * math.sin(alpha)
    x2, y2 = B * math.cos(beta), B * math.sin(beta)
    d = (x2-x1)**2 + (y2-y1)**2
    d = d ** 0.5
    return d

print solve(*rrm())

Solution (Python):
import math
a, b, h, m = map(int, input().split())
dh = (30 * h) + ((30 * m) / 60)
dm = (6 * m)
diff = abs(dh - dm)
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())
x=abs(30*h-(m*11)/2)
c=a**2+b**2-2*a*b*(math.cos(math.radians(x)))
print(c**0.5)

Solution (Python):
import math
 
a, b, h, m = map(int, input().split())
a_h = h*30 + m*0.5
a_m = m* 6
angle = abs(a_h-a_m)
 
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle))))

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

h_d = h*30 + m/2
m_d = 6*m

theta = abs(h_d - m_d)
if theta > 180:
    theta = 360 - theta
print((a**2 + b**2 - 2*a*b*cos(radians(theta)))**0.5)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
a = math.radians((H/12+M/720) * 360)
b = math.radians(M/60 * 360)

ax = math.sin(a)*A
ay = math.cos(a)*A
bx = math.sin(b)*B
by = math.cos(b)*B

ans = math.sqrt(abs(ax-bx)**2 + abs(ay-by)**2)
print(ans)

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

a_theta = math.radians(30*h) + math.radians(m/60*30)
b_theta = math.radians(6*m)

a_x = a*math.cos(a_theta)
a_y = a*math.sin(a_theta)
b_x = b*math.cos(b_theta)
b_y = b*math.sin(b_theta)

d = math.sqrt((a_x - b_x)**2 + (a_y -b_y)**2)
print(d)

Solution (Python):
import math
A,B,H,M = map( int ,input().split())
time = H*60+M
Ax = time/720
Bx = (time%60)/60
A_num = 12*Ax
B_num = 12*Bx
aasin = math.sin(math.radians(abs(A_num-B_num)*30))
aacos = math.cos(math.radians(abs(A_num-B_num)*30))
As = A*aasin
Bs = B - A*aacos
c = math.sqrt(As**2 + Bs**2)
print(c)

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

import math
if h == 0 and m == 0:
    hang = 360
else:
    hang = 1/12*h*360 + 1/60*m*30
if m == 0:
    mang = 360
else:
    mang = 1/60*m*360

ang = min(abs(hang-mang), abs(mang-hang))
c2 = a**2 + b**2 -2*a*b*math.cos(ang*math.pi/180)
print(math.sqrt(c2))

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

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

minutes = H*60+M

sita_h = (np.pi/360)*minutes
sita_m = (np.pi/30)*minutes

H_za = (A*np.cos(sita_h), A*np.sin(sita_h))
M_za = (B*np.cos(sita_m), B*np.sin(sita_m))

print(np.sqrt( np.square(H_za[0]-M_za[0]) + np.square(H_za[1]-M_za[1])) )

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)