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):
A,B,H,M=map(int,input().split())
import math

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

if m>=h:
    p=m-h

else:

    p=h-m


if p==0:
    print(abs(A-B))

else:

    l=math.radians(p)

    ans=(A**2+B**2-2*A*B*math.cos(l))**(1/2)

    print(ans)

Solution (Python):
import math

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

m=H*60+M
theta=(360/60*11/12*m) % (360)
print(math.sqrt(A**2+B**2-2*A*B*math.cos(theta/180*math.pi)))

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

Asita = time / 720
Bsita = (time % 60) / 60
sita = abs(Asita - Bsita) * 2 * math.pi

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

if sita <= math.pi * 0.5:
  Ans = ( A**2 + B**2 - 2 * A * B * abs(math.cos(sita)))**0.5
else:
  Ans = ( A**2 + B**2 + 2 * A * B * abs(math.cos(math.pi - sita)))**0.5
print(Ans)

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


M_kakudo = 6 * M

if(H>=12):
  H = H-12
H_kakudo = 30 * H
H_kakudo = M*1/2 + H_kakudo



kakudo = abs(H_kakudo-M_kakudo)


import math

a_2 = 0
a_2 = A*A + B*B - 2*B*A*math.cos(math.radians(kakudo))
import numpy
print(numpy.sqrt(a_2))

Solution (Python):
import sys
import math
a,b,h,m = map(int, sys.stdin.readline().rstrip("\n").split())
l_d = 6*m
s_d = 30*h + 0.5*m
d = abs(l_d-s_d)
cosC = round(math.cos(math.radians(d)), 13)
c_2 = a**2 + b**2 -2*a*b*cosC
c = round(c_2**0.5, 13)
print(c)

Solution (Python):
import math

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

jikan=math.pi*(h*60+m)/360

hun=math.pi*m/30

kakudo=jikan-hun

cos=math.cos(kakudo)
nijo=a**2+b**2-2*a*b*cos
if(nijo<=0):
    print(0)
else:
    print(nijo**(1/2))

Solution (Python):
import math
def colon(a, b, h, m):
  hour = 0.5 * (h * 60 + m) 
  minute = 6 * m
  angle = abs(hour - minute)
  angle = min(360 - angle, angle)
  rad = angle*(3.141592653589793238/180)
  
  ans = math.sqrt(a**2+b**2-(2*a*b*(math.cos(rad))))
  return ans
  

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

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



hkaku=float(h*30)+float(m*0.5)


mkaku=float(m*6)


kaku=abs(hkaku-mkaku)

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

c=math.sqrt(c2)
print(c)

Solution (Python):
import math

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

h_ang = h*360/12+m*30/60
m_ang = m*360/60

if h_ang - m_ang > 180:
  ang = m_ang-h_ang
  if ang < 0:
    ang += 360
else:
  ang = h_ang-m_ang
  if ang < 0:
    ang += 360
    
ans = a*a+b*b-2*a*b*math.cos(math.radians(ang))
    
print(math.sqrt(ans))

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

t = (H*1/6-M*11/360)*math.pi

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

print(C**0.5)

Solution (Python):
a,b,h,m=map(int,input().split())
import math
H=h*30+m*0.5
M=m*6
k=max((H-M),(M-H))
print((a**2+b**2-2*a*b*math.cos(math.radians(k)))**(1/2))

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((abs((H%12)*30-5.5*M)))))))

Solution (Python):
import math

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


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

result = (a ** 2) + (b ** 2) - (2 * a * b * math.cos(math.radians(kakudo)))

print(math.sqrt(result))

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

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




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

rad_h = radians(deg_h)
rad_m = radians(deg_m)

x_h, y_h = cos(rad_h) * A, sin(rad_h) * A
x_m, y_m = cos(rad_m) * B, sin(rad_m) * B

d = sqrt((x_h - x_m) ** 2 + (y_h - y_m) ** 2)



print(d)

Solution (Python):

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


jishin = (H + (M / 60))/12
tanshin = (M / 60)
nasukaku = max(jishin * 360, tanshin * 360) - min(jishin * 360, tanshin * 360)
result = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(nasukaku)))
print(result)

Solution (Python):
    

import math

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

    ra = 2.0 * math.pi * (h / 12 + m / (12 * 60))
    ax = math.cos(ra) * a
    ay = math.sin(ra) * a

    rb = 2.0 * math.pi * (m / 60)
    bx = math.cos(rb) * b
    by = math.sin(rb) * b

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

    print(str(d) + '\n')


if __name__ == '__main__':
    main()

Solution (Python):
import math


def get_theta(H, M):
    M_theta = math.pi / 30 * M
    H_theta = math.pi / 6 * (H + M / 60)

    return min(abs(M_theta - H_theta), 2 * math.pi - abs(M_theta - H_theta))

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

theta = get_theta(H, M)
print(((B*math.cos(theta) - A)**2 + (B*math.sin(theta))**2)**0.5)

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

ap = h * 30 + m * 0.5
bp = m * 6

ang = abs(ap - bp)

if ang > 180:
    ang = 360 - ang

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

print(math.sqrt(ans))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
shi_ta1=(M/60)*360
shi_ta2=((H*60+M)/720)*360
shi_ta=shi_ta1-shi_ta2
answer=math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(shi_ta)))
print(answer)

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

kaku = abs(((H*60 + M)*0.5) - (M*6))
c = A**2 + B**2 - 2*A*B*math.cos(math.radians(kaku))
ans = c**0.5
print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
D=abs((H/12+M/(60*12)-M/60)*360)
if D==0:
    l=abs(A-B)
    print(l)
else:
    d=math.cos(math.radians(D))
    X=A**2+B**2-2*A*B*d
    x=math.sqrt(X)
    print(x)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
angle = abs((H*30 + M*0.5) - M*6)%360
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(angle*math.pi/180)))

Solution (Python):
import math


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


digh = (h + m/60) * (1/12) * 360
digm = m * 6



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

print(c2**0.5)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def theta(h, m):
    mr = m*6
    hr = h*30 + m/2

    if hr > mr:
        if hr - mr < 180:
            rad = radians(hr - mr)
        else:
            rad = radians(360 - hr + mr)
    else:
        if hr - mr < 180:
            rad = radians(mr - hr)
        else:
            rad = radians(360 - mr + hr)
    
    return rad


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

    print(sqrt(A**2 + B**2 - 2 * A * B * cos(theta(H, M)))) 


if __name__ == '__main__':
    main()

Solution (Python):
import math
A,B,H,M = map(int, input().split())
kakudo = 2 * math.pi * abs(M/60 - (H/12+M/720))
print((A*A+B*B-2*A*B*math.cos(kakudo))**0.5)

Solution (Python):
import math

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

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

dig = abs(360.0 * ( ( M / 60.0 ) - ( ( H * 60.0 + M )/ 720 ) ) )

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

print(C)

Solution (Python):
import math

A, B, H, M= map(int,input().split())
h = 30* H + 0.5 * M
m = 6 * M
ans = A*A + B*B -2*A*B*math.cos(math.radians(abs(h-m)))
p = ans**(1/2)

print(p)

Solution (Python):
import numpy

if __name__ == "__main__":
	hour_len, min_len, hours, minutes = map(int, input().strip().split(' '))
	angle_minute = 2 * numpy.pi * (minutes / 60)
	angle_hour = 2 * numpy.pi * (((hours * 60) + minutes) / 720)
	if angle_hour >= angle_minute:
		final_angle = angle_hour - angle_minute
	elif angle_minute > angle_hour:
		final_angle = angle_minute - angle_hour
	answer = (hour_len * hour_len) + (min_len * min_len) - (2 * min_len * hour_len * numpy.cos(final_angle))
	print(numpy.sqrt(answer))

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


a = abs((H + M/60) / 12 * 360 - (M / 60) * 360)
if a > 180:
    a = 360 - a

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

Solution (Python):
from sys import stdin
import math
a=stdin.readline().split()

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

pos1=(30*H)+(M/2)
pos2=(6*M)
AA=abs(pos1-pos2)
if AA>180:
    AA=360-AA

ans=math.sqrt(A*A+B*B-2*A*B*(math.cos(AA*(math.pi)/180)))
print(ans)

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


import math

tan = H/12*2*math.pi + M/60/12*2*math.pi
tyo = M/60*2*math.pi

cos = math.cos(tyo-tan)

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

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

x= abs(6*m-30*h-0.5*m)

import math
cos=math.cos(math.radians(x))
c= a**2+b**2-2*a*b*cos

print(c**(0.5))

Solution (Python):
import math

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

def Main(A, B, H, M):
    th1 = 2*math.pi/12
    th2 = 2*math.pi/60
    t1 = th1*H+(2*math.pi*M/(12*60))
    t2 = th2*M
    return math.sqrt((A*math.cos(t1)-B*math.cos(t2))**2 +
            (A*math.sin(t1)-B*math.sin(t2))**2)
          
                    
out = Main(A, B, H, M)
print('{:.20f}'.format(out))

Solution (Python):
import math

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

Solution (Python):
import numpy as np
import math

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


def H_angle(H, M):
    return H * 30 + 0.5 * M

def M_angle(M):
    return M * 6

angle = abs(H_angle(H, M) - M_angle(M))
if angle >= 180:
    angle = abs(360 - angle)
angle = math.radians(angle)

def compute(A, B, angle):
    A2 = np.square(A)
    B2 = np.square(B)
    AB = A * B
    cos = np.cos(angle)
    return A2 + B2 - 2 * AB * cos


print(np.sqrt(compute(A, B, angle)))

Solution (Python):
import numpy as np

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

h_th_1 = list(range(1, 61, 1))  
m_th = list(range(6, 361, 6))

if m != 0:
    th = ((h_th_1[m - 1] / 2) + 30 * (h) - m_th[m - 1])
    th = abs(min(th, 360 - th))
    
    

else:
    th = abs(min(360 - (30 * h), (30 * h) - 360))

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

Solution (Python):
import math
A, B, H, M = map(int, input().split())
J = H * 60 + M
all = 12 * 60
AAA = J / all
tan = AAA * 360
tyou = AAA * 12 * 360
kakudo = tan - tyou
ans = A**2 + B**2 - 2 * A * B * math.cos(math.radians(kakudo))
print(ans**(1 / 2))

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

import numpy as np

hour = 30*H + M/2

t = abs(hour-6*M)
if t >= 180:
  t = 360 - t

t = np.pi/180*t

ans2 = A**2 + B**2 - 2*A*B*np.cos(t)
print(np.sqrt(ans2))

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

tmp = (60*H+M)/(60*12) - M/60

rad = math.radians(tmp*360)
c2 = A*A + B*B - 2*A*B*math.cos(rad)
print(math.sqrt(c2))

Solution (Python):
import numpy as np

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

H_th = 360*((H+M/60)/12)
M_th = 360*M/60
th = np.abs(H_th-M_th)
if 180 <= th <= 360:
  th = 360-th
th = th*np.pi/180

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

Solution (Python):
import math

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

min = h + m/60
hour = min/12
min = (min%1)*360
hour = (hour%1)*360

x = abs(min-hour)

if  360 - x < x:
    x = 360 - x

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

Solution (Python):
import math

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

L = (2*math.pi*H + (math.pi*M)/30.0)
S = ((math.pi*H)/6.0 + (math.pi*M)/360.0)
ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(abs(L-S)))
print(ans)

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

h2min = H * 60 + M
s_long = 1/2 * h2min
s_short = 6 * M
if s_long >= s_short:
    small = s_short
    big = s_long
else:
    small = s_long
    big = s_short
d1 = big - small
d2 = 360 - big + small
if d1 <= d2:
    d = d1
else:
    d = d2
c = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(d)))
print(c)

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

hrad = math.pi*(h/6 + m/360)
mrad = math.pi*m/30

print(math.sqrt(a**2+b**2-2*a*b*math.cos(hrad-mrad)))

Solution (Python):
import math

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

sh=math.pi*(H+M/60)/6
sm=math.pi*M/30

s=abs(sh-sm)

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

print(C)

Solution (Python):
import math

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

hour_x = A * math.cos(2*p*(H + M/60) /12)
hour_y = A * math.sin(2*p*(H+ M/60)/ 12)

minuit_x = B * math.cos(2*p*M/60)
minuit_y = B * math.sin(2*p*M/60)

x_dis = (hour_x - minuit_x) ** 2
y_dis = (hour_y - minuit_y) ** 2

print(math.sqrt(x_dis + y_dis))

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

if 30*h+m/2-6*m>=0:
  x=30*h+m/2-6*m
else:
  x=6*m-30*h-m/2
  
print((a**2+b**2-2*a*b*math.cos(math.radians(x)))**(1/2))

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

theta_a = 2*np.pi * (h+(m / (60.0))) / (12.0)
theta_b = 2*np.pi * m / (60.0)


def pos(r, theta):
    return r*np.cos(theta), r*np.sin(theta)

x_a, y_a = pos(a, theta_a)
x_b, y_b = pos(b, theta_b)

d2 = (x_a - x_b)**2 + (y_a - y_b)**2
print(np.sqrt(d2))

Solution (Python):


from math import sin, cos, pi, sqrt

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

ma = m * pi * 2 / 60  
ha = (h + m / 60) * pi * 2 / 12  

hx = a * cos(ha)
hy = a * sin(ha)
mx = b * cos(ma)
my = b * sin(ma)

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

Solution (Python):
import math

[a, b, h, m] = [int(i) for i in input().split()]
rad = h/12*360+m/60*360/12 - m/60*360
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(rad))))

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

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

import math

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

Solution (Python):
def main():
    from builtins import int, map, list, print, min
    import sys, math
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A, B, H, M = input_number_list()

    minute = H * 60 + M
    hd = minute / 2 % 360
    md = M * 6 % 360
    sa = min(abs(hd - md), abs(md - hd))
    ans = (A ** 2) + (B ** 2) - (2 * A * B * math.cos(math.radians(sa)))
    ans = ans ** 0.5
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys,math
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

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


h = H*math.pi/6 +M/60 * math.pi/6
m = M*math.pi/30

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

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

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B, H, M = MAP()
    alpha = 30*H + M/2 - 6*M
    alpha = min(alpha, 360 - alpha)
    
    C2 = A*A + B*B - 2*A*B*cos(radians(alpha))
    print(sqrt(C2))


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

kakudo_a = h * (360.0 / 12) + m * (30.0 / 60)
kakudo_b = m * (360.0 / 60)
kakudo = abs(kakudo_b - kakudo_a)

if kakudo == 0:
        ans = abs(a - b)
elif abs(kakudo) % 180 == 0:
        ans = a + b
else:
        bx = b * math.cos(kakudo*math.pi/180)
        by = b * math.sin(kakudo*math.pi/180)
        ans = math.sqrt((a - bx)** 2 + by ** 2)
        
print(ans)

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

A,B,h,m=map(int,input().split())
res = 0

if (h == 12): 
        h = 0
if (m == 60): 
    m = 0
a1 = 0.5 * (h * 60 + m) 
a2 = 6 * m 
res = abs(a1 - a2) 
res = min(360 - res, res) 

t = A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(res))
t = t**0.5


print("{0:.15f}".format(t))

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

def rad(deg):
  return math.pi*deg/180.0

def h_deg(h,m):
  return 30*h+m/2

def m_deg(m):
  return 6*m
  
def hm_rad(h,m):
  return rad(abs(h_deg(h,m)-m_deg(m)))

def get_C(A,B,h,m):
  theta = hm_rad(h,m)
  return math.sqrt(A**2+B**2-2*A*B*math.cos(theta))
  
print(get_C(A,B,H,M))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tkakudo=(h * 60 + m) * 0.5
skakudo = m * 6
kakudo = min(360 - abs(tkakudo - skakudo), abs(tkakudo - skakudo))
rkakudo = math.radians(kakudo)

p = (a**2 + b**2 -2*a*b*math.cos(rkakudo))**0.5

print(p)

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

shita = (-h / 6 - m / 360 + 1 / 2) * math.pi
phi = (-m + 15) / 30 * math.pi

print(math.sqrt( math.pow(a * math.cos(shita) - b * math.cos(phi), 2) + math.pow(a * math.sin(shita) - b * math.sin(phi), 2) ))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
hun = m
ji = h*60 + hun


sita_do = ji*0.5 - hun*6
ans = a**2 + b**2 - 2*a*b*math.cos(math.radians(sita_do))
print(math.sqrt(ans))

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

ta = math.pi*(h+m/60)/6
tb = math.pi*(m)/30

print((a**2 + b**2 - 2*a*b*math.cos(ta-tb))**0.5)

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

Solution (Python):
import math

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

alpha = (60*A[2]+A[3])/60*30
beta = 6*A[3]

temp = abs(alpha - beta)

if temp <=180:
    theta = temp
else:
    theta = 360 - temp



temp2 = A[0]*A[0]+A[1]*A[1]-2*A[0]*A[1]*math.cos(theta/180*math.pi)

print(math.sqrt(temp2))

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

a = abs((M*6)-((H*30)+(M*0.5)))%360
b = math.radians(min(a,abs(360-a)))
ans = -2*A*B*math.cos(b)+A**2+B**2

print(math.sqrt(ans))

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

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







hth=pi/6*H+pi/360*M
mth=pi/30*M

if H>=0 and H<3:
    hx=A*cos(pi/2-hth)
    hy=A*sin(pi/2-hth)
    
    mx=B*cos(pi/2-mth)
    my=B*sin(pi/2-mth)
elif H>=3 and H<6:
    hx=A*cos(-pi/2+hth)
    hy=-A*sin(-pi/2+hth)
    
    mx=B*cos(-pi/2+mth)
    my=-B*sin(-pi/2+mth)
elif H>=6 and H<9:
    hx=-A*cos(3*pi/2-hth)
    hy=-A*sin(3*pi/2-hth)

    mx=-B*cos(3*pi/2-mth)
    my=-B*sin(3*pi/2-mth)
else:
    hx=-A*cos(-3*pi/2+hth)
    hy=A*sin(-3*pi/2+hth)
    
    mx=-B*cos(-3*pi/2+mth)
    my=B*sin(-3*pi/2+mth)
    
a = numpy.array([hx, hy])
b = numpy.array([mx, my])
u = b - a
print(numpy.linalg.norm(u))

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

print(math.sqrt(c2))

Solution (Python):
from math import *

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

y1 = sin(-H/6*pi+0.5*pi-M/60/6*pi)*A
x1 = cos(-H/6*pi+0.5*pi-M/60/6*pi)*A
x2 = cos(-M/30*pi+0.5*pi)*B
y2 = sin(-M/30*pi+0.5*pi)*B
print(sqrt((x2-x1)**2+(y2-y1)**2))

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

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

d = math.sqrt(((A*np.cos(h) - B*np.cos(m))**2)+((A*np.sin(h) - B*np.sin(m))**2))

print(d)

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


s = 6 * M


l = 30 * H + 0.5 * M


theta = max(s,l)-min(s,l)
kakudo = min(360-theta, theta)


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

ans = math.sqrt(ansans)

print(ans)

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

a1 = (30 * h) + (0.5 * m)
b1 = 6 * m

if a1 > b1:
    k = a1 - b1
else:
    k = b1 - a1

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

print(res)

Solution (Python):
import math
a,b,h,m = map(float, input().split())
rot = 5.5 * (60.0*h + m)
ang = rot%360
rad = ang * math.pi / 180
cal = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
ans = math.sqrt(cal)
print(ans)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10



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


total_minute = H * 60 + M

tyosin = 6 * total_minute % 360
tanshin = 0.5 * total_minute % 360

kakudo = abs(tyosin - tanshin)

if kakudo > 180:
    kakudo = 360 - kakudo

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

print(math.sqrt(C2))

Solution (Python):
from sys import stdin
from sys import setrecursionlimit
import math
setrecursionlimit(10 ** 7)

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

ado = ((h+(m/60))*30)%360
bdo = (m*6)%360

kakudo = min(abs(ado-bdo),360-abs(ado-bdo))

kotae = a**2+b**2-2*b*a*math.cos(math.radians(kakudo))

print(math.sqrt(kotae))

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

angle = radians(abs(360 / 12 * h + 360 / 12 / 60 * m - 360 / 60 * m))
print((a**2 + b**2 - 2*a*b*cos(angle))**0.5)

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


    if 0 <= h/6  + m/360 - m/30 <1:
        c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos((h/6 + m/360 - m/30)*math.pi))
    elif 1 <= h/6  + m/360 - m/30 <2:
        c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos((-h/6  - m/360+ m/30)*math.pi))
    elif -1 <= h/6 + m/360 - m/30 <0:
        c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos((-h/6 - m/360 + m/30)*math.pi))
    elif -2 <= h/6  + m/360 - m/30 <-1:
        c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos((h/6 + m/360 - m/30)*math.pi))
    print(c)


if __name__ == "__main__":
    main()

Solution (Python):
import math

a,b,h,m = map(int,input().split())
h = h*60
t = h+m
at = t*0.5
bt = (t*6)%360
k = abs(at-bt)
cos = math.cos(math.radians(k))

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

Solution (Python):
"""
~~ Author : Bhaskar
~~ Dated : 16~05~2020
"""

import sys
from math import *
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


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


def main():
    a, b, h, m = map(int, sys.stdin.readline().split())
    angle = calcAngle(h, m)*(pi/180)
    ans = sqrt(a ** 2 + b ** 2 - (2 * a * b * cos(angle)))
    print(ans)


if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()

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

Solution (Python):
import numpy as np
a, b, h, m = map(int, input().split())
h %= 12
m %= 60
th1 = (h/12)*360+0.5*m
th2 = (m/60)*360
th = 0
if th1 > th2:
    th = th1 - th2
else:
    th = th2 - th1
if th > 180:
    th = 360 - th

th *= (np.pi/180)
c = np.sqrt(a**2+b**2-2*a*b*np.cos(th))
print(c)

Solution (Python):

import math


import sys
input = sys.stdin.readline



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

    temp1 = (H * 60 + M) / 2
    temp2 = M * 6

    if temp1 >= temp2:
        theta = temp1 - temp2
    else:
        theta = temp2 - temp1

    if theta == 0:
        res = max(A-B,B-A)
    else:
        res = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(theta))
        
        res = math.sqrt(res)

    

    print(res)



main()

Solution (Python):
import sys
import math
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
A,B,H,M = LI()

tanshin = H * 30 + M * 0.5;
shouhshin = M * 6;
diff = min(abs(tanshin-shouhshin),360.0-abs(tanshin-shouhshin))

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

Solution (Python):
import math

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

pos_x_long = a*math.sin(math.radians(30*h+0.5*m))
pos_x_short = b*math.sin(math.radians(6*m))

pos_y_long = a*math.cos(math.radians(30*h+0.5*m))
pos_y_short = b*math.cos(math.radians(6*m))

print(math.sqrt(pow(pos_x_long - pos_x_short,2) + pow(pos_y_long - pos_y_short,2)))

Solution (Python):

import sys
import math


def solve(A: int, B: int, H: int, M: int):
    long = 360/60 * M
    long_x = math.sin(math.radians(long))*B
    long_y = math.cos(math.radians(long))*B
    short = 360/12 * H + 30/60 * M
    short_x = math.sin(math.radians(short))*A
    short_y = math.cos(math.radians(short))*A
    print(math.sqrt((long_x - short_x) ** 2 + (long_y - short_y) ** 2))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    H = int(next(tokens))  
    M = int(next(tokens))  
    solve(A, B, H, M)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
import math

if __name__ == '__main__':
    a, b, h, m = tuple(map(int, input().split()))
    t = h + m/60
    w = (2 - 1/6) * t
    w %= 2

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

Solution (Python):
a,b,h,m=map(int,input().split())
from math import pi,cos,radians
time=h*60+m
bst=m/30
ast=(h*60+m)/360
st=abs(bst-ast)
if st>=1:
  st=2-st
elif st==0:
  print(abs(a-b))
  exit(0)


print((a**2+b**2-2*a*b*cos(radians(st*180)))**0.5)

Solution (Python):
import math
a, b, h, m = map(int , input().split())
tyousin = 30 * h + (30 * m / 60)
tansin = 6 * m
shita = abs(tyousin - tansin)
x = (a*a) + (b*b) - (a * b * 2 * math.cos(math.radians(shita)))
x = pow(x, 0.5)
print(x)

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

Solution (Python):
import math

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

c = (h - (m*11/60))*30

x = (a**2) + (b**2) - (2*a*b*math.cos(math.radians(c)))

ans = math.sqrt(x)

print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
b = 6*M  
a = (M+(60*H))/2 
r = abs(a-b) 
if r >180:
  r = 360-r
cosr = math.cos(math.radians(r))
t = ((A*A)+(B*B)-(2*A*B*cosr))**(1/2)
print(t)

Solution (Python):
import math
import sys
a, b, h, m = map(int,sys.stdin.readline().rstrip().split())
deg = min(abs(30*h - 5.5*m),360-abs(30*h - 5.5*m))
rad=math.radians(deg)
c = math.sqrt(a**2 + b**2 -2*a*b*math.cos(rad))
print(f'{c:.9f}')

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

deg_a = (a*math.cos(2*math.pi*(h*60+m)/720),a*math.sin(2*math.pi*(h*60+m)/720))
deg_b = (b*math.cos(2*math.pi*m/60),b*math.sin(2*math.pi*m/60))




print(((deg_a[0]-deg_b[0])**2+(deg_a[1]-deg_b[1])**2)**0.5)

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

ti=h*30+m*0.5
oo=m*6



kakudo = abs(ti-oo)-max(0,(abs(ti-oo)-180)*2)




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

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

x = abs(1/60  - 1 /(12*60))*(60*H+M) * 360
y = math.radians(x)

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

print(math.sqrt(C))

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

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

ang1 = 360 * (H/12) + 30 * (M/60)
ang2 = 360 * (M/60)
ang = abs(ang1-ang2)

ans = A**2 + B**2 -2*A*B*cos(radians(ang))
print(sqrt(ans))

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


if M==0 or M==60:
    m_deg = 0
else:
    m_deg = (M/60) *360

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

theta_deg = max(m_deg, h_deg) - min(m_deg, h_deg)
theta_rad = theta_deg*np.pi/180

cos_theta = np.cos(theta_rad)

C_2 = A**2 + B**2 - 2*B*A*cos_theta

print(C_2**0.5)

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

import math

x1, y1 = a, 0
x2, y2 = b, 0

alph = (h*60 + m)/(12*60) * 360
beta = m/60 * 360

x1 = a * math.cos(math.radians(alph))
y1 = a * math.sin(math.radians(alph))

x2 = b * math.cos(math.radians(beta))
y2 = b * math.sin(math.radians(beta))

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

print(ans)

Solution (Python):
import math 

A,B,H,M = map(int,input().split())
PI = math.pi
Aradi = float(PI/6*H + PI*M/360)

Bradi = float(PI * M /30.0)

if abs(Aradi - Bradi) <= PI:
    theta =  abs(Aradi - Bradi)
else:
    theta = 2*PI - abs(Aradi - Bradi)

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

print(length)