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

k = 60*h + m

import math

if m <= 15:
    by = b * math.sin(math.radians(90-(6*m)))
    bx = b * math.cos(math.radians(90-(6*m)))
elif m > 15 and m <= 30:
    by = b * -(math.sin(math.radians(6*(m-15))))
    bx = b * math.cos(math.radians(6*(m-15)))
elif m > 30 and m <= 45:
    by = b * -(math.sin(math.radians(90-((6*m)-180))))
    bx = b * -(math.cos(math.radians(90-((6*m)-180))))
else:
    by = b * math.sin(math.radians((6*m)-270))
    bx = b * -(math.cos(math.radians((6*m)-270)))
    
if k <= 180:
    ay = a * math.sin(math.radians(90-((1/2)*k)))
    ax = a * math.cos(math.radians(90-((1/2)*k)))
elif k > 180 and k <= 360:
    ay = a * -(math.sin(math.radians(((1/2)*k)-90)))
    ax = a * math.cos(math.radians(((1/2)*k)-90))
elif k > 360 and k <= 540:
    ay = a * -(math.sin(math.radians(90-(((1/2)*k)-180))))
    ax = a * -(math.cos(math.radians(90-(((1/2)*k)-180))))
else:
    ay = a * math.sin(math.radians(((1/2)*k)-270))
    ax = a * -(math.cos(math.radians(((1/2)*k)-270)))

ans = math.sqrt((ax-bx)**2 + (ay-by)**2)
print('{:.11f}'.format(ans))

Solution (Python):



import math as mt

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

    theta1 = 30*H + M/2
    theta2 = 6*M

    xx = A**2 + B**2 - 2*A*B*mt.cos(mt.radians(theta2-theta1))
    print(mt.sqrt(xx))


if __name__ == '__main__':
    main()

Solution (Python):
import math  
a,b,x,y=map(int,input().split())  
z1=(y/60-x/12-y/(60*12))*math.pi*2  
z2=(x/12+y/(60*12)-y/60)*math.pi*2  
ka=min(abs(z1),abs(z2))  
ans=a**2+b**2-2*a*b*math.cos(ka)  
print(ans**0.5)

Solution (Python):
import math

def calc_angle(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

def resolve():
	a, b, h, m = map(int, input().split())
	ang = calc_angle(h, m)
	radi = math.radians(ang)
	v = (a**2 + b**2 - 2*a*b*math.cos(radi))**0.5
	print(v)
resolve()

Solution (Python):
import math

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

ax = 0.0
ay = 0.0
bx = 0.0
by = 0.0

c = math.sin(math.radians(h * 30 + m / 2))
d = math.cos(math.radians(h * 30 + m / 2))
e = math.sin(math.radians(m * 6))
f = math.cos(math.radians(m * 6))




ax = a * c
ay = a * d
bx = b * e
by = b * f




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

Solution (Python):
import math
import numpy

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


if h <= 3:
    hs = 90 - (h*30 + 30/60*m)
elif h <= 6:
    hs = h*30 + 30/60*m -90
elif h <= 9:
    hs = 270 - (h*30 + 30/60*m)
else:
    hs = h*30 + 30/60*m -270

if m <= 15:        
    ms = 90 - m*6
elif m <= 30:        
    ms = m*6 - 90
elif m <= 45:        
    ms = 270 - m*6
else:        
    ms = m*6 - 270




hx = a * math.cos(math.radians(hs))

hy = a * math.sin(math.radians(hs))
mx = b * math.cos(math.radians(ms))

my = b * math.sin(math.radians(ms))
if hs == 90:
    hx = 0
if ms == 90:
    mx = 0

if h <= 3:
    hy = hy * 1
elif h <= 6:
    hy = hy * -1
elif h <= 9:
    hx = hx * -1
    hy = hy * -1
else:
    hx = hx * -1

if m <= 15:        
    mx = mx * 1
elif m <= 30:        
    my = my * -1
elif m <= 45:        
    mx = mx * -1
    my = my * -1
else:        
    mx = mx * -1







c = numpy.array([hx, hy])
d = numpy.array([mx, my])
u = d - c
print(numpy.linalg.norm(u))

Solution (Python):
from math import cos, pi

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

total_time = H * 60 + M

theta = float(abs(total_time / 2 - M * 6) * pi / 180)

c = pow(A ** 2 + B ** 2 - 2 * A * B * cos(theta), 1/2)

print(c)

Solution (Python):
import math
n=input()
n=n.split()
for i in range(0,len(n)):
        n[i]=int(n[i])
angle = abs(n[2]+n[3]/60 - n[3]/5)*30
if(angle > 180):
    angle=360 - angle
angle=math.pi*angle/180.00000
c=(n[0]**2) + (n[1]**2)- (2*n[0]*n[1]*math.cos(angle))
print(float(math.sqrt(c)))

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

hun=6*M
ji=30*H+(1/2)*M

if math.radians(hun-ji)==0:
    a=abs(A-B)
elif hun-ji==180 or ji-hun==180:
    a=A+B
else:
    a = (A ** 2 + B ** 2 - 2* A * B * math.cos(math.radians(hun-ji))) ** (1 / 2)
print(a)

Solution (Python):
import math

list = input().split()

A = int(list[0])
B = int(list[1])
H = int(list[2])
M = int(list[3])


r1 = 90 - (H * 30) - (M * 0.5)
if r1 < 0:
	r1 = 360 + r1


r2 = 90 - (M * 6)
if r2 < 0:
	r2 = 360 + r2


rdiff = r1 - r2
if rdiff < 0:
	rdiff = r2 - r1
if rdiff > 180:
	rdiff = 360 - rdiff


l = math.sqrt((A*A) + (B*B) - (2*A*B*math.cos(math.radians(rdiff))))

print(l)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h_=h*30+m*30/60
m_=m*6
p=abs(h_-m_)
if p>=180:
    p=360-p
ans=a**2+b**2-2*a*b*math.cos(math.radians(p))
print((ans)**0.5)

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False


def clockangles(hour, minute):
    ans = abs((hour * 30 + minute * 0.5) - (minute * 6))
    return min(360-ans,ans)


def main():
    A, B, H, M = MI()

    if M == 0 and H == 0:
        print(abs(A - B))
        return

    d = clockangles(H, M)
    r = math.radians(d)
    ans = A**2 + B**2 - 2 * A * B * math.cos(r)
    print(math.sqrt(ans))

    
    
    
    

    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
import math
A, B, H, M = map(int, input().split())
sA = (60*H+M)/360*math.pi
sB = M/30*math.pi
Ax = A*math.cos(sA)
Bx = B*math.cos(sB)
Ay = A*math.sin(sA)
By = B*math.sin(sB)
res = math.sqrt((Ax-Bx)**2+(Ay-By)**2)
print(res)

Solution (Python):
import math
A,B,L,M=list(map(int,input().split()))
minkakudo=6*M
jikankakudo=(L*60+M)*360/(12*60)
kakudo=abs(jikankakudo-minkakudo)
if kakudo>180:
    kakudo=360-kakudo
kakudo=math.radians(kakudo)
ans=A**2+B**2-(2*A*B*math.cos(kakudo))
print(ans**(0.5))

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
 
 
doubledt = abs(60*H - 11*M)
t = 0
if(doubledt > 360):
    t = math.pi * (720-doubledt)/360
else:
    t = math.pi * doubledt/360
 
tlen = math.sqrt(A*A + B*B - 2*A*B*math.cos(t))
print('{:.20f}'.format(tlen))

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

p = 0
o = 0
for i in range(1, H+1):
    p += 30
for q in range(1, M+1):
    o += 6
y = M * 0.5
p = p + y
C = p - o

H = abs(o - p)
total = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(H)))
print(total)

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

ans2 = A*A + B*B - 2 * A * B * math.cos(math.radians((((H*30)+(M/12*6) - M*6))))
ans = math.sqrt(ans2)
print(ans)

Solution (Python):
import math
a,b,h,m = map(int, input().split())
s = 30 * h + m * 0.5
l = m*6
x = abs(s-l)
if x >= 180: x = 360-x
c = math.cos(math.radians(x))
print((a**2+b**2-2*a*b*c)**0.5)

Solution (Python):
import math

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

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

Solution (Python):
import math
A,B,h,m=map(int,input().split())
time=60*h+m
a=(0.5*time)%360
b=(6*time)%360
x=abs(a-b)
if x==0 or x==360:
  c=abs(A-B)
elif x==180:
  c=A+B
else:
  c=math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(x)))
print(c)

Solution (Python):
import math

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

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

diff = abs(short -long)

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

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

print(math.sqrt(C))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
rad = math.radians((abs(((h / 12.0)+(m/60.0/12.0)) - (m / 60.0)) * 360))
print(math.sqrt((math.cos(rad)*a-b)**2 + (math.sin(rad)*a)**2))

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
chou_len, tan_len, nan_ji, nan_pun = map(int, input().split())
nan_ji_kaku = 30*nan_ji + nan_pun*30/60
nan_pun_kaku = 6*nan_pun

kaku = abs(nan_ji_kaku-nan_pun_kaku)

if kaku > 180:
  kaku = 360-kaku
if(kaku == 0):
    print(abs(chou_len-tan_len))
elif(kaku == 180):
  print(chou_len+tan_len)
else:
  kai = math.sqrt(chou_len*chou_len + tan_len*tan_len
                - 2 * chou_len*tan_len*math.cos(kaku*math.pi/180))
  print(kai)

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
from numpy import linalg as LA
import math

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

hh=-(h/12+m/720)*360+90
mm=-m/60*360+90
hx=math.cos(math.radians(hh))*a
hy=math.sin(math.radians(hh))*a
mx=math.cos(math.radians(mm))*b
my=math.sin(math.radians(mm))*b

x=np.array([hx-mx,hy-my])
print(LA.norm(x))

Solution (Python):

import math
a, b, h, m = map(int, input().split())
h = 30*h
m = 6*m
h += m/12
delta = abs((h-m)*math.pi/180)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(delta)))

Solution (Python):
import math
abhm = input('')
a=int(abhm.split(' ')[0])
b=int(abhm.split(' ')[1])
h=int(abhm.split(' ')[2])
m=int(abhm.split(' ')[3])

hx=360/12*h + 360/(12*60)*m
mx=360/60*m



angle = abs(hx-mx)
if angle > 180:
    angle = abs(angle-360)

c2 = pow(a,2) + pow(b,2) - 2*a*b*math.cos(math.radians(angle))


print(math.sqrt(abs(c2)))

Solution (Python):
import math
from math import cos


def time():
    A, B, H, M = map(int, input().split())
    minuteAngel = M * 360.0 / 60.0
    hourAngel = H * 30.0 + M * 30.0 / 60.0
    angel = abs(hourAngel - minuteAngel)
    a = cos(angel / 180 * math.pi)
    a = float('%.20f' % a)
    distance = math.sqrt(A * A + B * B - 2 * A * B * a)
    print("%.20f" % distance)


if __name__=="__main__":
    time()

Solution (Python):
import math
in1 = input().split()
A = float(in1[0])
B = float(in1[1])
H = float(in1[2])
M = float(in1[3])
aH = 0.5 * (H * 60 + M)
aM = 6*M
ra = abs(aH-aM)
ra1 = min(360 - ra, ra)
C2 = ((A*A)+(B*B))- (2*(A*B))*(math.cos(math.radians(ra1)))
print(math.sqrt(C2))

Solution (Python):
import math
pi=3.1415926535897932
a,b,h,m=map(int,input().split())
ad=h*30+m*0.5
bd=m*6.0
x=min(abs(ad-bd),360.0-abs(ad-bd))
if abs(x-180.0)<0.0000000001:
    print(a+b)
    exit()
elif abs(ad-bd)<0.000000001:
    print(abs(a-b))
    exit()
ans=a**2+b**2-(2*a*b*math.cos(math.radians(x)))
print(ans**0.5)

Solution (Python):
import math

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

angle = (30 * H + 0.5 * M) - (6 * M)
if angle < 0:
    angle *= -1

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

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

print(math.sqrt(x))

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

short = (h *(360/12)) + m *(1/2)
long  = m * (360/60)
rad = abs(long - short)
cosa = math.cos(math.radians(rad))
ans = a**2 + b**2 + (-2)*a*b*cosa
print(math.sqrt(ans))

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

def main():
    a, b, h, m = map(int, input().split())
    deg = abs(6*m-(30*h+m/2))
    if not deg:
        print(abs(a-b))
    elif deg == 180:
        print(a+b)
    else:
        deg = deg if deg < 180 else 360 - deg
        y = dec(math.radians(deg))
        x = dec(math.sqrt(dec(a**2 + b**2 - dec(2*a*b)*dec(math.cos(y)))))
        print(x)

if __name__ == "__main__":
    main()

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

H_len, M_len, H, M = map(int, input().split())







M_deg = 2*pi * M / 60
H_deg = 2*pi * (60 * H + M) / 12 / 60

deff = 0.0

deff = abs(M_deg - H_deg)

ans = sqrt(H_len ** 2 + M_len ** 2 - (2 * H_len * M_len * cos(deff)))

print(ans)

Solution (Python):
import numpy as np


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


short_x = np.sin((((H*30)+(M*0.5))/180)*np.pi)*A
short_y = np.cos((((H*30)+(M*0.5))/180)*np.pi)*A

long_x = np.sin(((M*6)/180)*np.pi)*B
long_y = np.cos(((M*6)/180)*np.pi)*B

ans = abs(short_x - long_x)**2 + abs(short_y - long_y)**2

ans = np.sqrt(ans)

print(ans)

Solution (Python):
import math

a,b,h,m = map(int, input().split())
if h == 0:
  angle = math.radians(5.5*m)
else:
  angle = angle = math.radians(h * 30 - 5.5*m)
  
x = math.sqrt(a**2 + b**2 -2 * a * b * math.cos(angle))
print(x)

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

import math

hour_v = 2 * math.pi / 12
min_v = 2 * math.pi / 60

hour_ang = (h + (m/60)) * hour_v
min_ang = m * min_v

if hour_ang < min_ang:
    theta = min_ang - hour_ang
else:
    theta = hour_ang - min_ang


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

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

H_deg = H*30 + M*0.5
M_deg = M*6
if M_deg <= H_deg:
    degree = H_deg - M_deg
else:
    degree = M_deg - H_deg

if degree == 180:
    print(A+B)
elif degree < 180:
    c = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(degree)))
    print(c)
else:
    c = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(360-degree)))
    print(c)

Solution (Python):
import math

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

bb = math.pi * m / 30.
aa = math.pi * (h+m/60.) / 6.
print(math.sqrt((b*math.sin(bb)-a*math.sin(aa))
                ** 2 + (b*math.cos(bb)-a*math.cos(aa))**2))

Solution (Python):
import math

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

h=(H%12)+(M%60)/60.0
x0=A*math.sin(math.pi*2*h/12.0)
y0=A*math.cos(math.pi*2*h/12.0)
x1=B*math.sin(math.pi*2*(M%60)/60.0)
y1=B*math.cos(math.pi*2*(M%60)/60.0)


print(((x0-x1)**2+(y0-y1)**2)**.5)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
c2 = m * 360 / 60
c1 = h * 360 / 12 + (1 * c2 / 12)
clis = [c1, c2]
C = max(clis) - min(clis)





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

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

mins = m / 60.0 * 360
hour = (h / 12.0 * 360) + 30 * (m / 60.0)





tar = abs(hour - mins)
if (tar == 0):
    ans = abs(a - b)
elif (tar == 180):
    ans = a + b
else:
    if (0 < tar < 180):
        pass
    else:
        tar = 360 - tar
    TR = math.radians(tar)
    
    co = math.cos(TR)
    cc = a ** 2 + b ** 2 - 2 * b * a * co
    ans = float(cc ** 0.5)

print(ans)

Solution (Python):
import math


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

    degree_H = M * 0.5 + H * 30
    degree_M = M * 6

    if degree_H == 0 or degree_M == 0:
        tmp = max(degree_H, degree_M)
        if tmp > 180:
            degree = abs(180 - tmp)
        else:
            degree = tmp
    else:
        if degree_H <= 180 and degree_M >= 180:
            degree = 360 - degree_M + degree_H
        elif degree_M <= 180 and degree_H >= 180:
            degree = 360 - degree_H + degree_M
        else:
            degree = abs(degree_H - degree_M)

    radian = math.radians(degree)
    cos_AB = math.cos(radian)
    ans = A ** 2 + B ** 2 - 2 * A * B * cos_AB

    print(math.sqrt(ans))


resolve()

Solution (Python):
import numpy as np

def main():
    A, B, H, M = map(float, input().split())
    
    omega_short = 6*M 
    omega_long = 0.5*M+30*H
    diff_rad = np.abs(omega_long - omega_short)
    cos_theta = np.cos(np.deg2rad(diff_rad))
    res = (A**2 + B**2 - 2*A*B*cos_theta)**(1/2)
    print(res)
if __name__ == "__main__":
    main()

Solution (Python):
import math
A,B,H,M = map(int, input().split())
s1 = H*30+float(M/60)*30
s2 = M*6
sita = min(max(s1,s2)-min(s1,s2),(360-max(s1,s2))+min(s1,s2))
co = math.cos(math.radians(sita))
res = (B**2)+(A**2)+(-2*B*A*co)
print(math.sqrt(res))

Solution (Python):
import math

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

long_hand = M * 6
short_hand = (H * 60 + M) * 0.5

angle = abs(long_hand - short_hand)

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

print("{:.20}".format(math.sqrt(dist)))

Solution (Python):
import math


def main():
    A, B, H, M = list(map(float, input().split()))
    a = H * 30 + M / 2
    b = M * 6
    theta = abs(a - b)
    C = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
    c = math.sqrt(C)
    if theta == 180:
        c = A + B
    elif theta == 0:
        c = abs(A - B)
    print(c)


if __name__ == '__main__':
    main()

Solution (Python):
import math
def yo(a,b,th):
    thr = math.radians(th)
    cosa = math.cos(thr)
    tmp = float(a**2) + float(b**2) - float(2*b*a*cosa)
    re = float(math.sqrt(tmp))
    return re
A,B,h,m = map(int, input().split())
longdig = m * 6
shortdig = (h*60+m) * 0.5
theta = abs(longdig - shortdig)
print(yo(A,B,theta))

Solution (Python):
import math

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

lm = (M*6)
sh = (H*30)
sm = (M*0.5)
s = sh+sm
r = abs(s-lm)
k = min(r, 360-r)

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

print(ans)

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




s_spin=PI*(H+M/60)*30/180
l_spin=PI*M*6/180


S=np.array([A*np.sin(s_spin),A*np.cos(s_spin)])
L=np.array([B*np.sin(l_spin),B*np.cos(l_spin)])



u=L-S
length2=np.linalg.norm(u)
print(length2)

Solution (Python):
import math

a, b, h, m = map(int, input().split())
hour = 0.5 * (h * 60 + m)
minute = 6 * m

angle = abs(hour - minute)
angle = min(360 - angle, angle)
ans = a**2 + b**2 - 2*a*b*math.cos(math.radians(angle))
ans = ans**0.5
print(ans)

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

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


h = h + m/60
theta = 2*pi/12*h


phi = 2*pi/60*m

dx = a * cos(theta) - b * cos(phi)
dy = a * sin(theta) - b * sin(phi)
dis = ((dx**2)+(dy**2))**0.5
print(dis)

Solution (Python):
import numpy as np

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

cita = abs(((360/(12*60)) * (h*60+m)) - ((360/60) * m))
if(cita > 180):
	cita = abs(cita - 360)
cita = np.radians(cita)
ans = (a**2)+(b**2)-(2*a*b*(np.cos(cita)))
ans = np.sqrt(ans)

print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
hkakudo=h*30+(m/2)
mkakudo=m*6
if hkakudo == 0:
    hkakudo = 360
if mkakudo == 0:
    mkakudo = 360
kakudo = abs(hkakudo-mkakudo)
print(math.sqrt(a**2+b**2-(2*a*b*math.cos(math.radians(kakudo)))))

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

sqa = i[0] * i[0]
sqb = i[1] * i[1]
angh = 30 * i[2]
angm = 6 * i[3]
angh += 0.5 * i[3]
theta = abs(angh - angm)
if theta > 180:
  theta = 360 - theta
ans = math.sqrt(sqa + sqb -2 * i[0] * i[1] * math.cos(theta * math.pi / 180))
print(ans)

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

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

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

deg = min(abs(h-m), abs(m-h))

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

print(sqrt(ans))

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

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

input = sys.stdin.readline


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

    theta_A = radians(30 * (H + M / 60))
    x_A = A * cos(theta_A)
    y_A = A * sin(theta_A)

    theta_B = radians(6 * M)
    x_B = B * cos(theta_B)
    y_B = B * sin(theta_B)

    ans = sqrt((x_A - x_B)**2 + (y_A - y_B)**2)
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
import math
a,b,h,m=map(int, input().split())
L=float(6*m)
l=float(30*h+m/2)
x=0
x=min(abs(L-l),360-abs(L-l))/180
c=a**2+b**2-2*a*b*math.cos(x*math.pi)
print(math.sqrt(c))

Solution (Python):
import numpy as np

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

th_a = 30*H + 0.5 * M
th_b = 6*M

theta = th_a -th_b

if theta <= 0:
  theta = -theta
if theta >= 180:
  theta = 360 - theta

if theta == 0:
  if A >= B:
    print(A-B)
  else:
    print(B-A)

elif theta == 180:
  print(A+B)

else:
  print(np.sqrt(A**2 + B**2 - 2*A*B*np.cos(theta*np.pi/180)))

Solution (Python):
import math
from decimal import *

def main():
    A,B,H,M = map(int, input().split())
    t1=30*H+M/2
    t2=6*M
    
    
    
    
    
    c=Decimal(math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(t1-t2))))
    print(c)
main()

Solution (Python):
import math


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

pi = math.pi
Hrad = (H+(M/60))*2*pi/12
Mrad = M*2*pi/60

d = abs(Hrad-Mrad)



if d >= pi:
    d = 2*pi - d



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

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

print((a**2+b**2-(2*a*b*math.cos(math.radians(h*30 - m*5.5))))**0.5)

Solution (Python):


import sys
import math

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

h_ras = (30 * H) + (M/2)
m_ras = 6 * M
h_m_ras = abs(h_ras - m_ras)
if h_m_ras == 0:
    print(abs(A-B))
    sys.exit()
ans = A * A + B * B - ((2* A * B * math.cos(math.radians(h_m_ras))))
print(math.sqrt(ans))

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

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

h = (H%12) / 12 * 360 + .5 * M
m =  M / 60 * 360
radian = math.cos(math.radians(abs(h-m)))
ans = math.sqrt(A**2 + B**2 - 2 * A * B * radian)
print('{:.15f}'.format(ans))

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

a = 6*M
b = 30*H + 0.5*M

if a==b:
    print(abs(A-B))
    exit()
elif a < b:
    dif = b - a
else:
    dif = a - b

if int(dif) == 180:
    print(A+B)
else:
    deg = dif
    print(math.sqrt(pow(A,2)+pow(B,2)+(-2*A*B*math.cos(math.radians(deg)))))

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

a_x = a * math.cos(math.radians(90 - 30 * h - 0.5 * m))
a_y = a * math.sin(math.radians(90 - 30 * h - 0.5 * m))

b_x = b * math.cos(math.radians(90 - 6 * m))
b_y = b * math.sin(math.radians(90 - 6 * m))





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

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, cos, sin, pi
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

A, B, H, M = map(int, input().split())
from decimal import Decimal, getcontext
getcontext().prec = 2000

A = Decimal(A)
B = Decimal(B)
H = Decimal(H)
M = Decimal(M)
mi = 60*H + M
pi = Decimal(math.pi)
a = pi * mi / 360
b = 6*M * pi / 180

cosv = Decimal(cos(b)*cos(a) + sin(b)*sin(a))
C = pow(A, 2) + pow(B, 2) - 2*A*B*cosv
C = C**Decimal(1/2)
print(float(C))

Solution (Python):
i = list(map(int, input().split()))
a = i[0]
b = i[1]
h = i[2]
m = i[3]

minute = 60*h + m

thetaa = 0.5 * minute
thetab = 6 * m

import math
ax = a*math.cos(math.radians(thetaa))
ay = a*math.sin(math.radians(thetaa))
bx = b*math.cos(math.radians(thetab))
by = b*math.sin(math.radians(thetab))

long = (ax-bx)**2 + (ay-by)**2

l = math.sqrt(long)

print(l)

Solution (Python):
import math

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

theta = 2*math.pi*abs((h/12+m/60/12)-m/60)
if theta > math.pi:
    theta = 2*math.pi - theta

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

Solution (Python):
import math

a, b, h, m = map(int, input().split())
h = (h + m // 60) % 12
m %= 60

r1, r2 = h * 30, m % 60 * 6
r1 += r2 / 360 * 30
r = r1 - r2

if r == 0:
    print(abs(a - b))
elif abs(r) == 180:
    print(a + b)
else:
    res = r1 - r2
    if res > 180:
        res = 360 - res
    elif res < - 180:
        res += 360
    elif res < 0:
        res = - res

    cos = math.cos((res / 360) * 2 * math.pi)
    print((a * a + b * b - 2 * a * b * cos) ** 0.5)

Solution (Python):
import math
a,b,h,m = list(map(int,input().split()))
long = (h*60+m)/(12*60) * 360 * math.pi/180
short = m/60 * 360 * math.pi/180
h_x = math.cos(long) * a
h_y = math.sin(long) * a
m_x = math.cos(short) * b
m_y = math.sin(short) * b

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

Solution (Python):
import math

A,B,H,M = map(int,input().split())
rad = (H*30 + M * 0.5 )  - M * 6
a = A**2 + B**2 - (2 * A * B * math.cos(math.radians(rad)))
print(a**0.5)

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

HH = math.pi*s/21600
MM = math.pi*s/1800

degH = math.degrees(HH)
degM = math.degrees(MM)

if degH > degM:
    X = degH - degM
elif degH == degM:
    X = 0
else:
    X = degM - degH
if X > 180:
    X = 360 - X
cos = math.cos(math.radians(X))
ans = (A**2) + (B**2) - (2*A*B*cos)
print(math.sqrt(ans))

Solution (Python):
import math


def main():
    A, B, H, M = map(int, input().split())
    H += M / 60
    H, M = H / 12 * 2 * math.pi, M / 60 * 2 * math.pi
    theta = H - M if H > M else M - H
    theta = 2 * math.pi - theta if theta > math.pi else theta
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import math

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

min_args = m*6
h_args = (h*60 + m)*0.5
arg = max(min_args - h_args, h_args - min_args)
rad = math.radians(arg)
c_2 = a**2 + b**2 - 2*a*b*math.cos(rad)
ans = math.sqrt(c_2)
print(ans)

Solution (Python):
import math

a, b, H, M = map(int, input().rstrip().split())
if H == 0 and M == 0:
    print(abs(a-b))
else:
    H = H * 5 + (float(M) / 12)
    kakudo = abs(H - M)
    kakudo *= 6
    print(math.sqrt(float(a * a) + float(b * b) - 2 * a * b * math.cos(math.radians(kakudo))))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
time= 60*h + m
H=time*0.5
M=(time*6) % 360
angle=abs(H-M)
ans=(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))**(1/2)
print(ans)

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

h = 360 * H / 12 + 30 * M / 60
m = 360 * M / 60

kakudo = h - m
if kakudo >= 180:
  kakudo = 360 - kakudo

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

print(math.sqrt(ans))

Solution (Python):
import math

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

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

p, q = max(H, M), min(H, M)
r = min(p-q, (360-p)+q)
c = round(math.radians(r), 40)
l = A ** 2 + B ** 2 - 2 * A * B * math.cos(c)
print(math.sqrt(l))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
H *= 5
deg =abs(H+(M/12)-M)*6
deg = min(360-deg, deg)
if deg==0:
    print(abs(B-A))
    exit()
elif deg==180:
    print(A+B)
    exit()
else:
    cos = math.cos(math.radians(deg))
    print(((A**2)+(B**2)-2*A*B*cos)**0.5)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
tan_kaku = H * 30 + M * 0.5
cho_kaku = M * 6
tan_x = math.cos(math.radians(tan_kaku)) * A
tan_y = math.sin(math.radians(tan_kaku)) * A
cho_x = math.cos(math.radians(cho_kaku)) * B
cho_y = math.sin(math.radians(cho_kaku)) * B
print(math.sqrt((tan_x - cho_x)**2 + (tan_y - cho_y)**2))

Solution (Python):
import math
lists = list(map(int,input().split()))
A = int(lists[0])
B = int(lists[1])
H = int(lists[2])
M = int(lists[3])
T = 60 * H + M
a = T / 2
b = 6 * M
c = b - a

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

Solution (Python):
import math


def main():
    a,b,h,m = list(map(int, input().split()))
    short = 0
    
    short = (h * 30) + (m * 0.5)
    long = m * 6
    ka = max(short, long) - min(short, long)
    ka = 360 - ka if ka > 180 else ka
    if ka == 90:
        print(math.sqrt(a**2+b**2))
        exit()
    else:
        print(math.sqrt(a**2 + b**2 - 2*(a*b) * math.cos(math.radians(ka))))


if __name__ == '__main__':
    main()

Solution (Python):
import math

x = input('').split()
x = [int(i) for i in x]
a = x[0]
b = x[1]
h = x[2]
m = x[3]

def root(value):
    return(value ** 0.5)


a_x = a * math.cos(2 * math.pi * ((h + m / 60) / 12))
a_y = a * math.sin(2 * math.pi * ((h + m / 60) / 12))
b_x = b * math.cos(2 * math.pi * (m / 60))
b_y = b * math.sin(2 * math.pi * (m / 60))  

x_x = ((b_x - a_x) ** 2)
y_y = ((b_y - a_y) ** 2)
print(root(x_x + y_y))