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())
X = 0
Y = 0
YY = 0
Z = 0
s = 60*H+M

a = 0.5*s
b = (6*s)%360

c = abs(a-b)

if(c<= 180):
    X = c
else:
    X = 360-c

sin = math.sin(math.radians(X))

cos = math.cos(math.radians(X))


if (X == 90):
    Y = A
    Z = B**2+Y**2
    print(math.sqrt(Z))
elif(X ==180):
    print(A+B)
else:
    Y = A*sin
    YY = B-A*cos
    Z = YY**2 + Y**2
    print(math.sqrt(Z))

Solution (Python):
import math

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

H_th = 30 * (H + M/60) 
M_th = 6 * M

if(H_th > M_th):
    th = abs(H_th - M_th)
elif(M_th == 0):
    th = abs(360 - H_th)
elif(H_th == 0):
    th = abs(360 - M_th)
else:
    th = abs(M_th - H_th)


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

Solution (Python):
import math
A,B,H,M= list(map(int, input().split(' ')))
print(math.sqrt(A**2+B**2-2*A*B*math.cos((M*6-(H*30+M*0.5))*3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977/180)))

Solution (Python):
import math
a, b, h, k = map(int, input().split())
kakudo_h = (0.5 * 60 * h) + (0.5 * k)
kakudo_k = 6 * k
ans = 0
ans2 = 0
kakudo = 0

if abs(kakudo_k-kakudo_h) == 180 or abs(kakudo_h-kakudo_k) == 180:
  ans = a + b
elif kakudo_h == kakudo_k:
  ans = abs(b - a)
elif kakudo_h > kakudo_k:
  if kakudo_h - kakudo_k > 180:
    kakudo = 360 - (kakudo_h - kakudo_k)
    ans2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))
    ans = ans2 ** 0.5
  else:
    kakudo = kakudo_h - kakudo_k
    ans2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))
    ans = ans2 ** 0.5
elif kakudo_h < kakudo_k:
  if kakudo_k - kakudo_h > 180:
    kakudo = 360 - (kakudo_k - kakudo_h)
    ans2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))
    ans = ans2 ** 0.5
  else:
    kakudo = kakudo_k - kakudo_h
    ans2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo))
    ans = ans2 ** 0.5

print(float(ans))

Solution (Python):

import numpy as np


def solve(*args: str) -> str:
    a, b, h, m = map(int, args[0].split())

    ax = a*np.sin(np.pi*(h+(m/60))/6)
    ay = a*np.cos(np.pi*(h+(m/60))/6)

    bx = b*np.sin(np.pi*m/30)
    by = b*np.cos(np.pi*m/30)

    return str(np.sqrt(pow(bx-ax, 2) + pow(by-ay, 2)))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Solution (Python):
import math

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

p = float(math.pi)
h_sita = h*p/6 + m*p/360
m_sita = m*p/30
cosine = math.cos((h_sita - m_sita))
c = (a**2 + b**2 - 2*a*b*cosine)**(0.5)
print(c)

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

Solution (Python):
import math
a,b,h,m = [int(x) for x in input().split()] 
x = (h*60+m)/2  
y = 6*m   
angle = abs(x - y)  
angle = min(360 - angle, angle) 
pi = 3.14159265358979323
k = math.pi/180
if angle==180:
    print(a+b)
    
elif(angle==0):
    print(abs(a-b))
    
else:
    angle = angle*k
    p = math.cos(angle)
    if(p<-1):
        p=0
    ans=pow(a,2)+pow(b,2)- 2*a*b*p;
    ans = math.sqrt(ans);
    print(ans)

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

jik=float(30*h+0.5*m)
jik=float(-jik+90)
hunk=float(6*m)
hunk=float(-hunk+90)
jizax=float(a*math.cos(math.radians(jik)))
jizay=float(a*math.sin(math.radians(jik)))
hunzax=float(b*math.cos(math.radians(hunk)))
hunzay=float(b*math.sin(math.radians(hunk)))
x=numpy.array([jizax,jizay])
y=numpy.array([hunzax,hunzay])
u=y-x
print(numpy.linalg.norm(u))

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

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

Ai = A*exp(((H+M/60)/12*2*math.pi)*1j)
Bi = B*exp(((M)/60*2*math.pi)*1j)
ans = abs(Ai-Bi)
print(ans)

Solution (Python):
from math import cos, sqrt
pi = 3.141592653589793238
a, b, H, M = map(int, input().split())
h, m = (2*pi*(H+M/60))/12, (2*pi*M)/60
if h-m < pi:
	x = h-m
else:
	x = 2*pi - h+m
print(sqrt(a*a + b*b - 2*a*b*cos(x)))

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

Solution (Python):
import numpy as np

A, B, H, M = map(int, input().split())
delta_min = 360 / 60
deg_min = delta_min * M
delta_hour = 360 / 12
delta_min_in_hour = 30 / 60
deg_hour = delta_hour * H + delta_min_in_hour * M

hour_X = A * np.sin(np.deg2rad(deg_hour))
hour_Y = A * np.cos(np.deg2rad(deg_hour))
min_X = B * np.sin(np.deg2rad(deg_min))
min_Y = B * np.cos(np.deg2rad(deg_min))

print(np.sqrt((hour_X - min_X)**2 + (hour_Y-min_Y)**2))

Solution (Python):
import math
def main():
  A,B,H,M = map(int, input().split())
  H_DO=(H*60+M)*360/(12*60)
  M_DO=M*6
  if(H_DO>M_DO):
    sabu=H_DO-M_DO
  elif(H_DO<M_DO):
    sabu=M_DO-H_DO
  else:
    sabu=0
  L=(A*A)+(B*B)-2*A*B*math.cos(math.radians(sabu))
  C=math.sqrt(L)
  print(C)
  
if __name__ == '__main__':
    main()

Solution (Python):
import math

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

angle = ((H * 30) + (M * 0.5)) - (M * 6)
ans = math.sqrt(A**2 + B**2 - (2*A*B*math.cos(math.radians(angle))))

print(ans)

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

t = abs((H/12 + (M/60)/12) - M/60)
print( math.sqrt( A**2 + B**2 - 2*A*B*math.cos(2*math.pi*t) ) )

Solution (Python):
import math

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


j = 360/(12*60) * (h*60+m)


f = 360/60 * m


beta = abs(j-f)


if beta>180:
    beta = 360-beta

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

Solution (Python):
import numpy as np

def main():
    A, B, H, M = map(int, input().split())
    r = M * 12 - (H * 60 + M)
    theta = (r*np.pi) / 360.0
    C = np.sqrt(A*A + B*B - 2*A*B*np.cos(theta))
    print(C)

if __name__ == '__main__':
    main()

Solution (Python):
import math
 
A,B,H,M = map(int,input().split())
angh = H*30+M*0.5
angm = M*6
ang = abs(angh - angm)%360
C = (A**2+B**2-2*A*B*math.cos(math.radians(ang)))**0.5
 
print(C)

Solution (Python):
import math

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


A_kaku = 30*(H)+0.5*(M)
B_kaku = 6*M
kaku = abs(A_kaku - B_kaku)
kaku = min(kaku,360-kaku)
kaku = math.radians(kaku)
X2 = A*A + B*B - 2*A*B*math.cos(kaku)
X2 = math.sqrt(X2)
print(X2)

Solution (Python):
import math

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

d = h * 30
if d / 5.5 > m:
    d -= 5.5 * m
else:
     d = 5.5 * m - d 



if d == 180:
    print(a + b)
elif d == 0:
    if a > b:
        a, b = b, a
    print(b - a)
else:
    print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(d))))

Solution (Python):
import math
a,b,h,m = map(int , input().split())
long_needle =(5 * m)/60 + h * 5  
sort_needle = m
ans = math.sqrt(a**2 + b **2 - 2*a*b*math.cos(abs(math.pi*(long_needle-sort_needle))/30))
print(ans)

Solution (Python):

import math
from decimal import Decimal

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

tri_m = Decimal(360 / 60 * m )

tri_h = Decimal((360 / 12 * h) + (360 / 12 / 60 * m))


angle = tri_m - tri_h





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

print(str(ans))

Solution (Python):
import math


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

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

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

Solution (Python):
import math
import sys

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

if b>a:
    a,b = b,a

longd = 30*h + m/2
shortd = 360*m/60

if abs(longd-shortd) > 180:
    dist = 360-abs(longd-shortd)
elif longd-shortd==0:
    print(abs(a-b))
    sys.exit()
elif abs(longd-shortd) == 180:
    print(abs(a+b))
    sys.exit()
else:
    dist = abs(longd-shortd)

if dist < 90:
    print(math.sqrt((b*math.sin(math.radians(dist)))**2 + (a -b*math.cos(math.radians(dist)))**2))
elif dist == 90:
    print(math.sqrt(b**2 + a**2))
else:
    
    dist = 180 - dist
    print(math.sqrt((b*math.sin(math.radians(dist)))**2 + (a +b*math.cos(math.radians(dist)))**2))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
ji = (60 * H + M) / 2
hun = 6 * M

sa = ji - hun if ji > hun else hun - ji

if sa > 180:
    sa = 360 - sa
theta = math.radians(sa)



x = A - B * (math.cos(theta))
y = B * math.sin(theta)

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

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

a=math.radians(s)
h=A**2+B**2
minus=2*A*B*math.cos(a)
ans=(h-minus)**(1/2)
print(ans)

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

R = H/12 + M*0.5/360

r = M/60

Rad_c = np.cos((R-r)*2*np.pi)

C = np.sqrt(A*A + B*B -2*A*B*Rad_c)
print(C)

Solution (Python):
import math

a, b, h, m = map(int,input().split())
d = abs(0.5*(60*h+m) - 6*m)
if d > 180:
  d = 360 - d
c = math.cos(math.radians(d))
e = a*a + b*b - 2*a*b*c
f = math.sqrt(e)
print(f)

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

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

t1 = h * 30
t1 = m / 2 + t1
t2 = m * 6
r = abs(t1 - t2)
if r > 180:
    r = 360 - r
rr = math.cos(math.radians(r))
print(math.sqrt(a*a + b*b - 2*a*b*rr))

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

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

Solution (Python):
import math

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



w=abs(360*(a[2]*60+a[3])/720 - 360*a[3]/60) 
cosw=math.cos(math.radians(w))

l=math.sqrt(a[0]**2 + a[1]**2 - 2*a[0]*a[1]*cosw)

print(l)

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

A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md) * (math.pi/180)
X = sqrt(A**2 + B**2 - (2*B*A * cos(Cd)))
print(X)

Solution (Python):
import math

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

angle_h = 30 * (h + m / 60)
angle_m = 6 * m

angle = abs(angle_h - angle_m)
if angle > 180:
    angle = 360 - angle

bx = math.cos(math.radians(angle)) * b
by = math.sin(math.radians(angle)) * b

print(math.sqrt(((bx - a)**2) + (by**2)))

Solution (Python):
import math

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


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





if Ar < 90:
  Ax = A * math.sin(math.radians(Ar))
  Ay = A * math.cos(math.radians(Ar))
elif Ar >= 90 and Ar < 180:
  Ar = Ar - 90
  Ax = A * math.cos(math.radians(Ar))
  Ay = -1 * A * math.sin(math.radians(Ar))
elif Ar < 270:
  Ar = Ar - 180
  Ax = -1 * A * math.sin(math.radians(Ar))
  Ay = -1 * A * math.cos(math.radians(Ar))  
else:
  Ar = Ar - 270
  Ax = -1 * A * math.cos(math.radians(Ar))
  Ay = A * math.sin(math.radians(Ar))


if Br < 90:
  Bx = B * math.sin(math.radians(Br))
  By = B * math.cos(math.radians(Br))
elif Br >= 90 and Br < 180:
  Br = Br - 90
  Bx = B * math.cos(math.radians(Br))
  By = -1 * B * math.sin(math.radians(Br))
elif Br < 270:
  Br = Br - 180
  Bx = -1 * B * math.sin(math.radians(Br))
  By = -1 * B * math.cos(math.radians(Br))  
else:
  Br = Br - 270
  Bx = -1 * B * math.cos(math.radians(Br))
  By = B * math.sin(math.radians(Br))  

X = abs(Bx-Ax)
Y = abs(By-Ay)  


Ans = ((X**2) + (Y**2))**0.5
print(Ans)

Solution (Python):
import numpy as np

i = list(map(int, input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]
arg1 = (float((h * 60 + m)*2)/float((12 * 60)))
arg2 = float(m*2 )/60
arg = abs(arg1 - arg2) * np.pi
print(np.sqrt(a*a + b*b - 2*a*b*np.cos(arg)))

Solution (Python):
import math
PI = 3.141592653589793
def degRad(deg):
	return deg * PI / 180.0

a, b, H, M = map(float, input().split())
time = H + M / 60.0

hAngle = 2.0 * PI * time / 12.0
y1 = a * math.cos(hAngle)
x1 = a * math.sin(hAngle)

mAngle = 2.0 * PI * time
y2 = b * math.cos(mAngle)
x2 = b * math.sin(mAngle)

dist = math.sqrt(math.pow(x1 - x2, 2) + math.pow(y2 - y1, 2))
print(round(dist, 9))

Solution (Python):
import math
list1=list(map(int,input().strip().split()))[:4]
a,b,h,m=list1[0],list1[1],list1[2],list1[3]
angle=(0.5*(h*60+m))-(6*m)
an=(math.pi/180)*angle
c=math.sqrt((a**2)+(b**2)-(2*a*b*math.cos(an)))
print(c)

Solution (Python):
import math

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

pi2 = 2 * math.pi
theta = abs((pi2 * ((H/12)+(M/(60*12)))) - (pi2 * (M/60)))
if(theta >= math.pi):
  theta = pi2 - theta
c = math.sqrt((A ** 2) + (B ** 2) - (2 * A * B * math.cos(theta)))
print(c)

Solution (Python):
import math
A,B,H,M = map(float,input().split())
c = A*A + B*B - 2.0*A*B*math.cos(math.radians((11.0*M-60.0*H)/2))
print(math.sqrt(c))

Solution (Python):
import math
from fractions import Fraction
A, B, H, M = map(float, input().split())
a_th = (H+M/60)/12*2.0*math.pi

b_th = (M/60.0)*2.0*math.pi
ｔｈ = abs(a_th-b_th)
d = math.sqrt(A*A +B*B -2*A*B*math.cos(th))
print(d)

Solution (Python):
import math

def main():
    A,B,H,M = [int(x) for x in input().split()]
    degH = (0.5*H*60 + 0.5*M)
    degM = 6*M
    theta = abs(degH-degM)
    if theta == 180:
        print(A+B)
        return
    if theta > 180:
        theta = 180 - (theta - 180)
    
    
    print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(theta))))

if __name__ == '__main__':
    main()

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



r=abs((h*30+m*0.5)-(m*6))
s=math.sqrt(a**2+b**2-(2*a*b*(math.cos(math.radians(r)))))
print(s)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
s = 3600*h+60*m
r = 2*math.pi*s*(1/43200-1/3600)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r)))

Solution (Python):

import math

def pita(a, b, angle):
    return math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))

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

h_angle = h*30 + m*(1/2)
m_angle = m*6



angle = abs(h_angle - m_angle)

print(pita(a, b, angle))

Solution (Python):
import math

s = list(map(float,input().split()))

if(s[2] <= 12):
  dig = (360 * (s[2] / 12) + 30 * (s[3] / 60)) - 360 * s[3] / 60
else:
  dig = (360 * ((s[2] - 12) / 12) + 30 * (s[3] / 60)) - 360 * s[3] / 60

l = s[0] * s[0] + s[1] * s[1] - 2 * s[0] * s[1] * math.cos(math.radians(dig)) 
le = math.sqrt(l)

print(le)

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

A=int(A)
B=int(B)
H=int(H)
M=int(M)

kakudo_H = H*30 +M*0.5
kakudo_M = M*6
if M==0:
    kakudo_M=360

kakudo_sa=abs(kakudo_H-kakudo_M)

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

Solution (Python):
import math

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

"""
DegA = int(H*30 + M*0.5)
DegB = int(M*6)

if abs(DegA - DegB) < 180:
    Deg = DegA - DegB

else:

    if DegA > DegB:
        Deg = 360 - DegA + DegB

    else:
        Deg = 360 - DegB + DegA
"""   

Deg = math.radians(abs(0.5 * (60 * H + M) - 6 * M))

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

print(format(C,'.20f'))

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

Solution (Python):
import  math



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

Hr = H * 30 + M * 30 / 60
Mr = M * 6
Dr = abs(Hr - Mr)

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

Solution (Python):
import math
temp = list(map(int,input().split()))
a=temp[0]
b=temp[1]
h=temp[2]
m=temp[3]
htemp=float(h)+float(float(m)/float(60))
hdeg=math.pi*htemp/float(6)
mdeg=math.pi*float(m)/float(30)
deg=hdeg-mdeg
ans=math.sqrt((a*a)+(b*b)-2*a*b*float(math.cos(deg)))
print(ans)

Solution (Python):

import heapq
from fractions import gcd
from functools import reduce
from collections import deque

import itertools
import collections
import math
import sys
sys.setrecursionlimit(2000000)







a, b, h, m = list(map(int, input().split()))
if h >= 12:
    h -= 12
ms = 360*(m/60)
ns = 360*(h/12) + 30*(m/60)

mx = b*math.cos(math.radians(ms))
my = b*math.sin(math.radians(ms))
hx = a*math.cos(math.radians(ns))
hy = a*math.sin(math.radians(ns))

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

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

hkaku = h * 30 + m * 0.5
mkaku = m * 6

th = 0
if hkaku > mkaku:
    th = hkaku - mkaku
else:
    th = mkaku - hkaku
if th > 180:
    th = abs(th -360)

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

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


hrad = H*2*math.pi/12 + M/60*2*math.pi/12
mrad = M*2*math.pi/60

kakudo = min(2*math.pi - abs(hrad-mrad),abs(hrad - mrad))


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


print(math.sqrt(res))

Solution (Python):
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
import numpy as np

input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""
np.set_printoptions(precision=20)
a,b,h,k = m()

a = [0,a]

b = [0,b]

degb = np.deg2rad(90-(6 * k))
dega = np.deg2rad(90-(30 * h + 30*(k/60)))



cosb = np.cos(degb)
sinb = np.sin(degb)
cosa = np.cos(dega)
sina = np.sin(dega)



aa = [0,0]
bb = [0,0]

aa[0] = a[0] * cosa - a[1] * sina
aa[1] = a[0] * sina + a[1] * cosa
bb[0] = b[0] * cosb - b[1] * sinb
bb[1] = b[0] * sinb + b[1] * cosb




print(math.sqrt((aa[0]-bb[0])**2 + (aa[1]-bb[1])**2))

Solution (Python):
"""
hour hand = A cm
min hand = B cm

"""

from decimal import Decimal
from math import radians, cos, sqrt

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

ha = (((h + m / 60 ) % 12) / 12) * 360
ma = (m / 60) * 360
angle = abs(ha - ma)






res = sqrt(a**2 + b**2 - 2 * a * b * Decimal(cos(radians(angle))))

print(res)

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

long_bar = math.radians(((h*60+m)/720)*360)
short_bar = math.radians((m/60)*360)

shita = long_bar-short_bar

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

Solution (Python):
import math
from decimal import Decimal

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

a_deg = Decimal(30)*h+m/Decimal(2)
b_deg = Decimal(6)*m

delta_deg = abs(Decimal(a_deg-b_deg))%360
if delta_deg > 180:
    delta_deg = 360-delta_deg

theta = Decimal(delta_deg)*Decimal(math.pi)/Decimal(180)

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


print(c2**Decimal(0.5))

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

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

angle_a = 30 * H + 0.5 * M
angle_b = 6 * M

diff = abs(angle_a - angle_b)
if diff > 180:
    diff = 360 - diff

theta = radians(diff)

res = sqrt(A*A + B*B - 2 * A * B * cos(theta))

print(res)

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

needle = [h * 30 + m * 0.5, m * 6]
angle = max(needle) - min(needle) 
if angle > 180.0:
  angle = 360 - angle 
c2 = math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(math.radians(angle))
print('{:.11f}'.format(math.sqrt(c2)))

Solution (Python):
def resolve():
    import math

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

    theta = abs(((h + m/60)/12 - m/60) * math.pi * 2)
    if theta == 0:
        print(abs(a - b))
        return
    elif theta == math.pi:
        print(a + b)
        return
    theta = min(theta, 2 * math.pi - theta)
    cos_theta = math.cos(theta)
    c = math.sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos_theta))
    print(c)
resolve()

Solution (Python):
import math
a,b,h,m = map(int,input().split())
theta_h = 2 * math.pi * (h * 60 + m)/720
theta_m = 2 * math.pi * m /60
x_h = a *math.cos(theta_h)
y_h = a *math.sin(theta_h)
x_m = b *math.cos(theta_m)
y_m = b *math.sin(theta_m)
length = math.sqrt((x_h - x_m)*(x_h - x_m) + (y_h - y_m)*(y_h - y_m))


print(length)

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

HM=M/60
H=H+HM

H = H/12*360
M = M/60*360
cos = H-M

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


ans = A**2+B**2-(2*A*B*cos)

print(math.sqrt(ans))

Solution (Python):
import math

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

ml = m * 6
mp = m / 60
hl = h * 30 + 30 * mp



ras = abs(ml - hl)
if ras > 180:
    ras = 360 - ras


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

ans = math.sqrt(ans)

print(ans)

Solution (Python):
import math
from decimal import Decimal as d

a,b,h,m=map(int,input().split())
tyousin=d((h+m/60)/6*math.pi)
tanshin=d(m/30*math.pi)
rad=abs(tyousin-tanshin)
x=a**2+b**2-2*a*b*math.cos(rad)
ans=d(math.sqrt(x))
print(abs(ans))

Solution (Python):
import math 

def dosuu(h,m):
    rad=abs((2*math.pi)*((6*m-(30*h+m/2))/360))
    
    return rad

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

kaku=dosuu(h,m)

rad=math.cos(kaku)

long=(a**2+b**2-2*a*b*rad)**(1/2)
print(long)

Solution (Python):
A,B,H,M = (int(x) for x in input().split())
import math
Angle = (H*30+0.5*M)-M*6
if 180<Angle<=360:
    Angle = 360-Angle
Rad = math.radians(Angle)
Length = math.sqrt(A*A + B*B -2*A*B*math.cos(Rad))
print(Length)

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

import math

h_min=h*60
rad=5.5*(h_min+m)%360

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

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

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

CC = ((H * 60 + M) * 0.5) - (M * 6)
cc = math.cos(math.radians(CC))
XX = A ** 2 + B ** 2 - 2 * A * B * cc
print(math.sqrt(XX))

Solution (Python):
import math
import numpy as np

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

hRad = math.radians(30 * h + 0.5 * m)
mRad = math.radians(6 * m)

xH = a * math.cos(hRad)
yH = a * math.sin(hRad)
xM = b * math.cos(mRad)
yM = b * math.sin(mRad)

hH = np.array([xH, yH])
mM = np.array([xM, yM])

print(np.linalg.norm(hH-mM))

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


h = (math.pi/6*H%360) + (math.pi/360*M)
m = math.pi/30*M




ans = math.sqrt(A**2 + B**2 -(2*A*B*math.cos((math.pi/6*H%360) + (math.pi/360*M)-math.pi/30*M)))

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

Solution (Python):
import math

A,B,H,M=(int(x) for x in input().split())
X=(A*math.cos(M*math.pi/30)-B*math.cos(H*math.pi/6+M*math.pi/360))**2
Y=(A*math.sin(M*math.pi/30)-B*math.sin(H*math.pi/6+M*math.pi/360))**2
L=math.sqrt(X+Y)
print(L)

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

Solution (Python):
import math

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

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

angle_M = M * m
angle_H = (H * 60 + M) * h

angle = math.fabs(angle_M - angle_H)

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

print(length)

Solution (Python):
import math

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


A_degree = 30 * H + 0.5 * M
B_degree = 6 * M

diff_degree = A_degree - B_degree

diff_rad = math.radians(diff_degree)


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

Solution (Python):
import numpy as np
A, B, H, M = list(map(int, input().split()))
hth = (np.pi / 6.0) * H + (2.0*np.pi / (12*60)) * M
mth = (np.pi / 30.0) * M
hvec = A * np.array([np.cos(hth), np.sin(hth)])
mvec = B * np.array([np.cos(mth), np.sin(mth)])
tmp = np.linalg.norm(hvec - mvec)
print(tmp)

Solution (Python):





import math



 



a, b, h, m  = map(int, input().split())
if h>=12:
    h=h-12
'''

'''
'''
n = input()
a = [int(input()) for i in range(n)]
'''
'''
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
'''
 






t=min(abs((h+m/60)*30-m*6),abs(360-((h+m/60)*30-m*6)))
u=pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(t))

print(math.sqrt(u))

Solution (Python):

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




w = 0

w = h - m
if w > 180:
    w = w


elif w == 180:
    print(abs(A+B))
    exit()
elif w == 0:
    print(abs(A-B))
    exit()
else:
    pass


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

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

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

print(((a*cos(h*pi/6+m*pi/(360))-b*cos(m*pi/30))**2 + (a*sin(h*pi/6+m*pi/(360))-b*sin(m*pi/30))**2)**(1/2))

Solution (Python):

import math

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

db = M * 360 / 60
da = H *360/12 + db/12
dt = da-db

C2:float = A**2 + B**2 - 2*A*B*math.cos(math.radians(dt))
C = C2 ** 0.5

print(abs(C))

Solution (Python):
import math

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





hour = 60 * H + M


if M > 0:
    Long = 360 / (60 / M)
else :
    Long = 0

if hour == 0 :
    small = 0
else :
    small = 360 / (720 / hour)


theta = abs(Long - small)
if theta > 180 :
    theta = 360 - theta

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

X  = A ** 2 + B ** 2 - 2 * A * B * cosX
ans = X ** (1/2)
print(ans)

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



A,B,H,M = LI()

t = math.radians(5.5*(60*H+M))

x = A**2+B**2-2*A*B*math.cos(t)

print(math.sqrt(x))

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

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

rad_h = 90 - (h + (m/60))*30
rad_m = 90 - m*6

ax = a * math.cos(math.radians(rad_h))
ay = a * math.sin(math.radians(rad_h))

bx = b * math.cos(math.radians(rad_m))
by = b * math.sin(math.radians(rad_m))

ans = ((bx - ax)**2 + (by - ay)**2)**0.5

print(ans)

Solution (Python):
import  math
A,B,H,M = list(map(int,input().split()))
short_nid_degree = H * 30 + (0.5 * M)
long_nid_degree = M * 360 /60
diff_nid_degree =  abs(short_nid_degree - long_nid_degree)
if diff_nid_degree > 180:
    diff_nid_degree=360 - diff_nid_degree
c_2  = A**2 + B**2 - (2 * B * A * math.cos(math.radians(diff_nid_degree)))
c= math.sqrt(c_2)
print(f"{c:.20f}")

Solution (Python):
import math
from decimal import Decimal
a,b,h,m = map(int,input().split())
kakudo = abs((30*h+(m*(0.5)))-m*6)
k = min(kakudo,360-kakudo)


co = math.cos(math.radians(k))
nijo = a**2 + b**2 - 2*a*b*co


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

Solution (Python):
import math

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

kakuA = - (List[2] * 60 + List[3]) * 0.5 + 90
kakuB = - List[3] * 6 + 90

xA = List[0] * math.cos(math.radians(kakuA))
yA = List[0] * math.sin(math.radians(kakuA))
xB = List[1] * math.cos(math.radians(kakuB))
yB = List[1] * math.sin(math.radians(kakuB))

d = math.sqrt((xA - xB)**2 + (yA - yB)**2)

print(d)

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

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

s_theta =  m * 6
l_theta =  (h*60 + m)*0.5

if abs(s_theta - l_theta) > 180:
    theta = 360 - abs(s_theta - l_theta) 
else:
    theta = abs(s_theta - l_theta)

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

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

Solution (Python):
import math

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

thetaH = 30 * H + 0.5 * M
thetaM = 6 * M

theta = abs(thetaH - thetaM)

if theta >= 180:
    theta = 360 - theta

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

print(math.sqrt(C2))