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

def main():
    N = [int(_) for _ in input().split()]
    A = N[0]
    B = N[1]
    h = N[2]
    m = N[3]

    l = m * 6
    s = (((h * 30) % 360) + (30 * m / 60)) % 360

    angle = abs(s - l)
    if angle > 180:
        angle = 360 - angle

    if angle == 180:
        print(A+B)
    elif angle <= 90:
        sin = math.sin(math.radians(angle))
        cos = math.cos(math.radians(angle))
        if A > B:
            result=math.sqrt((B*sin)*(B*sin) + (A-B*cos)*(A-B*cos))
            print(result)
        else:
            result=math.sqrt((A*sin)*(A*sin) + (B-A*cos)*(B-A*cos))
            print(result)
    else:
        angle = 180 - angle
        sin = math.sin(math.radians(angle))
        cos = math.cos(math.radians(angle))
        if A > B:
            result=math.sqrt((B*sin)*(B*sin) + (A+B*cos)*(A+B*cos))
            print(result)
        else:
            result=math.sqrt((A*sin)*(A*sin) + (B+A*cos)*(B+A*cos))
            print(result)
        

if __name__ == "__main__":
    main()

Solution (Python):

import math

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

if h == 0: 
    angle = math.radians(5.5*m)
else:
    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
zishin = 30 * h + 0.5 * m 
tanshin = 6 * m

kakudo = abs(zishin - tanshin)

if kakudo >= 180:
    kakudo = 360 - kakudo

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

print(math.sqrt(dis))

Solution (Python):
import math

S = input().split()
A=float(S[0])
B=float(S[1])
H=float(S[2])
M=float(S[3])
siita=(H*60+M)/2-M*6;
if(siita>180):
    siita=360-siita
ans=math.sqrt(A*A+B*B-2*A*B*math.cos(siita*3.1415926535897932/180))
print(ans)

Solution (Python):
import math
a, b, h, m = [int(v) for v in input().split()]

rad = abs(((h * 60 + m) - (m * 12)) / (12 * 60) * math.pi * 2)
hyp = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(rad))
print(hyp)

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

import math



t = ((H * 60 + M) / 2 - M * 6)
if t == 90 or t == 270:
    print((A ** 2 + B ** 2) ** 0.5)
else:
    
    
    
    
    theta = t * math.pi / 180
    
    
    
    
    
    x = (B - A * math.cos(theta)) ** 2 + (A * math.sin(theta)) ** 2
    print(x ** 0.5)

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

deg_a = 30 * (h + m / 60)
deg_b = m * 6

theta = abs(deg_a - deg_b)
theta = min(360 - theta, theta)
out = math.pow(math.pow(a,2) + pow(b,2) - 2 * a * b * math.cos(theta * math.pi / 180.0), 0.5);

print(out)

Solution (Python):
import numpy as np
import decimal

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


h = (h /12) * 360 + 0.5 * m

m = (m / 60) * 360

x = 360 - abs(h-m)
y = abs(h-m)
x = min(x,y)

ans = float(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(np.radians(x))))

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

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


def main():
    A, B, H, M = map(int, input().split())
    x = abs(H * 30+M*0.5-M*6)
    theta = min(x, 360-x)
    rad = math.radians(theta)
    if theta == 180:
        print(A+B)
    elif theta == 0:
        print(abs(A-B))
    else:
        print(math.sqrt(A**2+B**2-2*A*B*math.cos(rad)))


if __name__ == '__main__':
    main()

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

theta1 = 30*H+30*(M/60)
theta2 = 360*(M/60)
theta  = abs(theta1-theta2)

print((A**2+B**2-2*A*B*math.cos(math.radians(theta)))**0.5)

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

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

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

print(math.sqrt(tmp))

Solution (Python):
A,B,H,M = map(int,input().split())
import math
 
d = 30*(H%12)+0.5*M -6*M
 
if d<0:
    d = -d
if d>180:
    d = 360 -d
 
 
c = A**2 + B**2 - 2*A*B*math.cos(math.radians(d))
 
print(math.sqrt(c))

Solution (Python):
import math
PI = math.pi

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

kakudo = (30*H - 5.5*M) * PI / 180
ans = (B**2 + A**2 - 2*A*B*math.cos(kakudo)) **(1/2)
print(ans)

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

Solution (Python):
import math

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

c=h*30+m*0.5
d=m*6

kakudo=0
if c>=d:
  kakudo=min(c-d,360-(c-d))
else:
  kakudo=min(d-c,360-(d-c))

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

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

print(ans)

Solution (Python):
import math

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

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

if H_arg - M_arg>=180:
    H_M_arg = (360-H_arg) + M_arg
else:
    H_M_arg = abs(H_arg - M_arg)



X = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(H_M_arg)))
print(X)

Solution (Python):

import math
a, b, h, m = map(int,input().split())
long = h * 30 + m * 0.5
short = m * 6
angle = abs(long - short)
if angle >= 180:
    angle2 = 360 - angle
else:
    angle2 = angle
x = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle2))
print(math.sqrt(x))

Solution (Python):
import math

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


hour_rad = (30*H)+(0.5*M)


minutes_rad = 6*M


clock_rad = 0
if abs(minutes_rad - hour_rad) <= 180:
    clock_rad = abs(minutes_rad - hour_rad)
else:
    clock_rad = 360 - abs(minutes_rad - hour_rad)





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

Solution (Python):
import math
A,B,H,M=map(int,input().split())
x=abs(30*H - 5.5*M)
cosx=math.cos(math.radians(x))
print(math.sqrt((A**2)+(B**2)-2*A*B*cosx))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
minute = m * 360 / 60
hours = (h * 360 / 12)
hours += m * 360 / 720
angle = abs(minute - hours)

if angle > 180:
    angle = 360 - angle
angle = math.radians(angle)
ans = math.sqrt((a**2) + (b**2) - (2*a*b*math.cos(angle)))
print(ans)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
ra = 2*math.pi * h / 12 + 2*math.pi / 12 * m / 60
rb = 2*math.pi * m / 60
ax, ay = a * math.cos(ra), a * math.sin(ra)
bx, by = b * math.cos(rb), b * math.sin(rb)
dx, dy = abs(ax - bx), abs(ay - by)
print(math.sqrt(dx*dx + dy*dy))

Solution (Python):
import math

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

lon = m * 360/60
tan = (h*60+m) * 360 / (12*60)
kaku = tan - lon

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

Solution (Python):
import math
a,b,h,m = map(int,input().split())
N = 360*m/60
M = 30*h + 30*m/60
siita = abs(N - M)
if siita >= 180:
  siita = 360 - siita
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians((siita))))
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((h/12+m/720-m/60)*2*math.pi))

print(c)

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

short, long, H, M = (int(x) for x in input().split())

angle = ((H*3600 + M*60) * pi/21600) - (M * 60 * pi/1800)

ans_2 = (short**2 + long**2 - 2*short*long*cos(angle)) ** (1/2)

print(ans_2)

Solution (Python):
import math

factor    = list(map(int, input().split()))
factor[2] = factor[2] * 30 + factor[3] * 0.5
factor[3] = factor[3] * 6
degree    = abs(factor[2] - factor[3])
radian    = math.radians(degree)

answer    = math.sqrt((factor[0]**2 + factor[1]**2) - 2*(factor[0] * factor[1]) * math.cos(radian))
print(answer)

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

def yogen(x):
    ans = (A ** 2 + B ** 2 - 2*A*B*math.cos(math.radians(x)))**(1/2)
    print("{:.20f}".format(ans))

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

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

if ji == hun:
    aaa = abs(A-B)
    print("{:.20f}".format(aaa))
elif ji - hun < 180:
    yogen(ji-hun)
else:
    yogen(hun-ji)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
h = h + m/60
Ac = a*math.cos(30*h*math.pi/180)
As = a*math.sin(30*h*math.pi/180)
Bc = b*math.cos(6*m*math.pi/180)
Bs = b*math.sin(6*m*math.pi/180)
x = (abs(As-Bs))
y = (abs(Ac-Bc))
print(math.sqrt(x**2+y**2))

Solution (Python):
import math

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






X_H = math.cos((((H / 12) + M/60/12)* math.pi * 2) * -1 + math.pi / 2) * A
Y_H = math.sin((((H / 12) + M/60/12)* math.pi * 2) * -1 + math.pi / 2) * A
X_M = math.cos(((M / 60) * math.pi * 2) * -1 + math.pi / 2) * B
Y_M = math.sin(((M / 60) * math.pi * 2) * -1 + math.pi / 2) * B





print(math.sqrt(((X_H - X_M) ** 2 + (Y_H - Y_M) **2)))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
H_deg = H*(math.pi)/6+M*math.pi/360
M_deg = M*(math.pi)/(3*10)
if H_deg >= M_deg:
    deg = H_deg - M_deg
else:
    deg = M_deg - H_deg
if deg >math.pi:
    deg = 2*(math.pi)-deg
c2=0
c2 = A*A+B*B-2*A*B*(math.cos(deg))
print(math.sqrt(c2))

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
 
m_rad = 360 / 60 * M
h_rad = 360 / 12 * H + (360 / 12 * M / 60)

rad = abs(m_rad - h_rad)

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

Solution (Python):

import numpy as np

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

rad_H = 2*np.pi*H/12 + 2*np.pi*M/12/60
rad_M = 2*np.pi*M/60


dif = rad_H - rad_M
if (np.abs(dif) > np.pi):
    dif = 2*np.pi - dif


AB = A**2 + B**2 - 2*A*B*np.cos(abs(dif))


print('{:.12f}'.format(np.sqrt(AB)))

Solution (Python):
import math

il = [int(k) for k in input().split()]
A = il[0]
B = il[1]
H = il[2]
M = il[3]

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

k = abs(h-m)



if k > 180:
    k = 360 - k

radian = math.radians(k)

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

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

Solution (Python):
import math

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

agh = 30*h + (m*360)/720
agm = 6*m
diff = abs(agh - agm) 
diff0 = min(diff, 360 - diff) 

if 5*h == m: 
    ans = abs(a - b)
if diff == 180: 
    ans = a + b
if diff0 <= 90:
    ref = max(a, b)*math.sin(math.radians(diff0))
    ref1 = max(a, b)*math.sin(math.radians(90 - diff0)) - min(a, b)
    ans = (ref**2 + ref1**2)**0.5
else:
    diff0 = 180 - diff0
    ref = max(a, b)*math.sin(math.radians(diff0))
    ref1 = max(a, b)*math.sin(math.radians(90 - diff0)) + min(a, b)
    ans = (ref**2 + ref1**2)**0.5

print(ans)

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

Solution (Python):
import math


def diff(xi, xj, yi, yj):
    x = (abs(xi - xj)) ** 2
    y = (abs(yi - yj)) ** 2
    return (x + y) ** 0.5


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


a_theta = 30 * h + 0.5 * m
b_theta = 6 * m
ax = math.cos(math.radians(a_theta)) * a
ay = math.sin(math.radians(a_theta)) * a
bx = math.cos(math.radians(b_theta)) * b
by = math.sin(math.radians(b_theta)) * b

ans = diff(ax, bx, ay, by)
print(ans)

Solution (Python):
import math
import numpy

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

X = abs(6*M - 0.5*M - 30*H)

if X > 180:
    X = 360 - X

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

Solution (Python):
import math
A,B,H,M = map(int, input().split())
H %= 12
M %= 60
dh = 360/12*(H+M/60)
dg = 360/60*M
th = max(dh,dg)-min(dh,dg)
print((A**2+B**2-2*A*B*math.cos(math.radians(th)))**0.5)

Solution (Python):
import math
def sann(n):
    print(math.sqrt(a**2+b**2-(2*a*b*(math.cos(math.radians(n))))))

a,b,c,d=map(int,input().split())
c=c*30+d*(1/2)
d=d*6
n=abs(c-d)

sann(n)

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

Solution (Python):
import math

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

h_rad = 30*h
h_rad += m*0.5
m_rad = 6*m
diff1 = abs(h_rad-m_rad)

diff2 = 360-diff1

diff = min(diff1,diff2)


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

Solution (Python):
import math
import numpy
time = input().split()
short = int(time[2])
longs = int(time[3])

short_niddle = (short*60 + longs)*360/(12*60)
long_niddle = longs*360/60


angle = abs(short_niddle-long_niddle)
if 180 <= angle:
    angle = 360 - angle
a = int(time[0])
b = int(time[1])

co = math.cos(math.radians(angle))
kotae = a**2 + b**2 -2*a*b*co
print(math.sqrt(kotae))

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

H_rad = ( H*30)+M/2 
M_rad  = (M *6)
A_x = A*math.sin(math.radians(H_rad))
A_y = A*math.cos(math.radians(H_rad))
B_x = B*math.sin(math.radians(M_rad))
B_y = B*math.cos(math.radians(M_rad))

sqr = math.pow(A_x -B_x ,2) + math.pow(A_y -B_y,2)

result = math.sqrt(sqr)

print(result)

Solution (Python):
import math

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

time = h*60 + m
ji = math.radians(time*0.5)
hun = math.radians(m*6)

ax = a*math.sin(ji)
ay = a*math.cos(ji)
bx = b*math.sin(hun)
by = b*math.cos(hun)

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

print(ans)

Solution (Python):
import math

a, b, h, m = map(int, input().split())
o = 0
c = (h*30) + (m/60*30) - (m*6)
c = math.radians(c)
print(((a**2)+(b**2)-2*a*b*(math.cos(c)))**(1/2))

Solution (Python):
import sys
from io import StringIO
import unittest
import math

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

    theta = abs(30 * h + 0.5 * m - 6 * m)

    
    

    ans = (pow(a,2) + pow(b,2) - 2 * a * b * math.cos(math.radians(theta))) ** 0.5
    print('{:.21g}'.format(ans))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 4 9 0"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 4 10 40"""
        output = """4.56425719433005567605"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
import math

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

tan=h*30+0.5*m
cho=6*m

kakudo=float(100)

if math.sqrt((tan-cho)*(tan-cho))>180:
	kakudo=360-math.sqrt((tan-cho)*(tan-cho))
	print(math.sqrt(a*a+b*b-2*a*b*(math.cos(math.radians(kakudo)))))

if math.sqrt((tan-cho)*(tan-cho))==180:
	print(a+b)

if math.sqrt((tan-cho)*(tan-cho))<180:
	kakudo=math.sqrt((tan-cho)*(tan-cho))
	print(math.sqrt(a*a+b*b-2*a*b*(math.cos(math.radians(kakudo)))))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
o = 0
c = (h*30) + (m/60*30) - (m*6)
c = math.radians(c)
print(((a**2)+(b**2)-2*a*b*(math.cos(c)))**(1/2))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tansin=[a*math.cos(math.radians(90-(30*h+(0.5*m)))),a*math.sin(math.radians(90-(30*h+(0.5*m))))]
chousin=[b*math.cos(math.radians(90-(6*m))),b*math.sin(math.radians(90-(6*m)))]
x=chousin[0]-tansin[0]
y=chousin[1]-tansin[1]
print((x**2+y**2)**0.5)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
ad=30*h+6*m/12
bd=6*m
ca=abs(ad-bd)
if 360-ca < ca:
    ca=360-ca
ans=a**2+b**2-(2*a*b)*math.cos(math.radians(ca))
print(math.sqrt(ans))

Solution (Python):
import math


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

theta_a_deg = (360/60) * (1/12) * m + (360/12) * h
theta_b_deg = (360/60) * m
theta_deg = abs(theta_a_deg - theta_b_deg)

cc = (a - b*math.cos(math.radians(theta_deg)))**2  + (b*math.sin(math.radians(theta_deg)))**2
print(abs(cc**0.5))

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

S=360*(M/60)
X=(H/12+M/720)*360
Y=abs(X-S)
Z=A**2+B**2-2*A*B*(math.cos(math.radians(Y)))
print(Z**0.5)

Solution (Python):
import numpy as np

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


deg_H = (H+ M/60)*(360/12)
deg_M = M*(360/60)
theta = deg_H - deg_M

if abs(theta) >= 180:
  if theta > 0:
    theta = deg_M + (360-deg_H)
  else:
    theta = deg_H + (360-deg_M)
else:
  theta = abs(theta)

C2 = A**2 + B**2 - 2*A*B*np.cos(np.deg2rad(theta))

print(np.sqrt(C2))

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

Solution (Python):
import math
def solve(a, b, h, m):

    deg_a = math.radians(0.5 * (h * 60 + m))
    deg_b = math.radians(6 * m)

    y_a = a * math.cos(deg_a)
    x_a = a * math.sin(deg_a)

    y_b = b * math.cos(deg_b)
    x_b = b * math.sin(deg_b)
    ans = math.sqrt((x_b - x_a)**2 + (y_b - y_a)**2)
    return ans

if __name__ == "__main__":
    a,b,h,m = [int(i) for i in input().split()]
    print(solve(a, b, h, m))

Solution (Python):
import math

def main():
    a,b,h,m = map(int, input().split())
    hd = math.pi/6*h + math.pi/360*m
    md = math.pi/30*m
    print(math.sqrt(a**2+b**2-2*a*b*math.cos(hd-md)))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import math

ABHM=np.array(input().split(" "),dtype=np.int32)

A=ABHM[0]
B=ABHM[1]
H=ABHM[2]
M=ABHM[3]

minutes=H*60+M
long_angle=6*minutes%360
small_angle=0.5*minutes%360

angle=0
if(long_angle>small_angle):
    angle=long_angle-small_angle
else:
    angle=small_angle-long_angle

if(angle==180):
    S=A+B
else:
    S=np.sqrt(pow(A,2)+pow(B,2)-2*A*B*np.cos(np.radians(angle)))
print(S)

Solution (Python):
from math import cos,radians, sqrt
a,b,h,m = map(int, input().split())
tan = h*(360//12)+(0.5*m)
naga = m*(360//60)
if abs(naga-tan) > 180:
    kakudo = 360 - abs(naga-tan)
else:
    kakudo = abs(naga-tan)
ans = sqrt(a**2 + b**2 - 2*a*b*cos(radians(kakudo)))

print(ans)

Solution (Python):
import math
A, B, H, M = list(map(int, input().split()))
angleS = (H * 60 + M) * 0.5
angleL = M * 6
C = abs(angleS - angleL)
answer = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(C)))
print(answer)

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

c = (a**2 + b**2 -2*a*b*math.cos(math.radians((h+m/60)*30-m*6)))

print(c**0.5)

Solution (Python):
import math

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

a1 = (2 * math.pi) * (h / 12) + (2 * math.pi) * (m / (60 * 12))
a2 = (2 * math.pi) * (m / 60)
diff = max(a1, a2) - min(a1, a2)
if diff > math.pi:
    diff = (2 * math.pi) - diff

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

Solution (Python):
import math

i = list(map(int, input().split()))
a=i[0]
b=i[1]
h=i[2]
m=i[3]
ans = a*a+b*b-2*a*b*math.cos((m/30-(h*60+m)/360)*math.pi)
print(math.sqrt(ans))

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

hour_angle = h * 30 + ((m/60)*30)

minute_angle = (m//5)*30 + ((m - ((m//5)*5))/5 * 30)
angle = max(hour_angle, minute_angle) - min(hour_angle, minute_angle)

if angle == 0:
  print(abs(a-b))
elif angle == 180:
  print(a+b)
else:
  print(math.sqrt(a**2 + b**2 - (2*b*a*math.cos(angle*math.pi/180))))

Solution (Python):
from math import cos, sqrt, radians
a, b, h, m = map(int, input().split())
angle = abs(h*30 - m*5.5)
angle = min(angle, 360 - angle)
angle = radians(angle)
c = sqrt(a**2 + b**2 - 2*a*b*cos(angle))
print(c)

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

Solution (Python):
from decimal import Decimal
import numpy as np

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

deg = h*30 + m/2 - m*6
length = Decimal(str(a*a + b*b - 2*a*b*np.cos(np.deg2rad(deg))))**Decimal('0.5')

print(length)

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

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

PI = 3.14159265359

theta_a = 2*PI*(h/12) + (2*PI/12)*(m/60)
theta_b = 2*PI*(m/60)

pa_x = a*cos(theta_a)
pa_y = a*sin(theta_a)
pb_x = b*cos(theta_b)
pb_y = b*sin(theta_b)

print(sqrt((pa_x-pb_x)**2+(pa_y-pb_y)**2))

Solution (Python):
from decimal import Decimal
import math

if __name__ == "__main__":
    a, b, h, m = map(float, input().split())
    
    pi = Decimal(math.pi)
    a = Decimal(a)
    b = Decimal(b)
    h = Decimal(h)
    m = Decimal(m)
    ang = pi / 30 * (m) - pi / 6 * ((h) + (m)/60)
    c = ( a**2 + b**2 - 2*a*b*Decimal(math.cos(ang)) )**Decimal(0.5)
    print(c)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
Short = (H * (360/12)) + M * 1/2
Long = M * (360/60)
angle = abs(Long - Short)
Angle = min(angle, (360 - angle))
print((A**2 + B**2 -2*A*B*math.cos(math.radians(Angle)))**0.5)

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

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

angle_h = 360 * (h / 12) + 30 * (m / 60)
angle_m = 360 * (m / 60)
angle = abs(angle_h - angle_m)
angle = angle if angle <= 180 else 360 - angle

ans = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(radians(angle))
print(sqrt(ans))

Solution (Python):
import math


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

    A_deg = (360 / 12) * H + (((360 / 12) / 60) * M)
    B_deg = (360 / 60) * M

    Ax = math.sin(math.radians(A_deg)) * A
    Ay = math.cos(math.radians(A_deg)) * A
    Bx = math.sin(math.radians(B_deg)) * B
    By = math.cos(math.radians(B_deg)) * B

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


if __name__ == "__main__":
    main()

Solution (Python):
import math
tempList = tuple(map(int, input().split()))
a = tempList[0]
b = tempList[1]
hour = tempList[2]
minute = tempList[3]
time = hour * 60 + minute
mypi = math.pi
hourAngle = time/(12*60)
minuteAngle = minute/60
diff = abs(hourAngle - minuteAngle)
if diff > 0.5:
    diff = 1 - diff
angle = diff * mypi * 2
result = a*a + b*b - 2*a*b*math.cos(angle)
print(math.sqrt(result))

Solution (Python):
from math import pi, cos
import math
s=input()	.split(" ")
a=float(s[0])
b=float(s[1])
h=float(s[2])
m=float(s[3])
mm=float(6*m)
gg=float((h*60+m)/2)
alf=float(abs(gg-mm))
if(alf>180):
	alf-=180
	alf=180-alf
alf=float(alf*pi/180)
x=a*a+b*b-a*b*2*cos(alf)
print("{:.12f}".format(math.sqrt(x)))

Solution (Python):
import math

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

h = 30*i[2]+(30*i[3]/60)
m = 6 * i[3]

g = abs(h-m)


s = i[0]**2+i[1]**2-2*i[0]*i[1]*math.cos(g*math.pi/180)
a = math.sqrt(s)
print(a)

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((h * 30 + m * 0.5) - (m * 6))))))

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

rot = (h * 30 + m * 0.5) / 360 * math.pi * 2

hx = math.sin(rot) * hl
hy = math.cos(rot) * hl

rot = m * 6 / 360 * math.pi * 2
mx = math.sin(rot) * ml
my = math.cos(rot) * ml

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

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

h = 360/12*H
h += 0.5*M
m = 360/60*M
C = abs(m-h)
print(math.sqrt(A**2+B**2-(2*A*B*math.cos(math.radians(C)))))

Solution (Python):
A,B,H,M=map(int,input().split())
import math
t=30*H-5.5*M
theta=min(t,360-t)
theta=theta*math.pi/180
L=math.sqrt(A**2+B**2-2*A*B*math.cos(theta))

print(L)

Solution (Python):
import math

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

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

if abs(angleH - angleM) < 180:
    angle = float(abs(angleH - angleM))
elif abs(angleH - angleM) > 180:
    if angleH > angleM:
        angle = float(360 - angleH + angleM)
    else:
        angle = float(360 - angleM + angleH)

elif abs(angleH - angleM) == 180:
    angle = 180
    
elif angleH==angleM:
    angle = 0


a2 = float(A**2 + B**2 - 2*A*B*math.cos(math.radians(angle)))
ans = float(a2**0.5)
print(f'{ans:.20f}')

Solution (Python):
import math

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

    ad = 360 * h / 12 + 30 * m / 60
    bd = 360 * m / 60

    if ad < bd:
        d = bd - ad
    else:
        d = ad - bd
    
    if d > 180:
        d = 360 - d

    cosc = math.cos(math.radians(d))
    ans = math.sqrt( a**2 + b**2 - 2*a*b*cosc)
    
    print(ans)
 
if __name__ == "__main__":
    main()

Solution (Python):
import math

long, short, h, m = map(int, input().split())

a_long = (float(30) * h) + ((1 / 2) * m)
a_short = float(6 * m)

rad = math.radians(a_long - a_short)


length = math.sqrt(long ** 2 + short ** 2 - 2 * long * short * math.cos(rad))
print(length)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
if 30*H-6*M>=0:
    y=abs(30*H-6*M)+M/2
else:
    y=abs(30*H-6*M)-M/2
if y==90 or y==270:
    ans=(A**2+B**2)**(0.5)
else:
    ans=(A**2+B**2-2*A*B*math.cos(math.radians(y)))**(0.5)
print(ans)

Solution (Python):

import sys
import math
import numpy as np

def solve(A: int, B: int, H: int, M: int):
    theta_m = math.radians(-M*360/60)
    theta_h = math.radians(-(H)*360/12) + theta_m / 12 

    x_m, y_m = B*math.cos(theta_m), B*math.sin(theta_m)
    x_h, y_h = A*math.cos(theta_h), A*math.sin(theta_h)

    print(math.sqrt((x_m-x_h)**2 + (y_m - y_h)**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 math

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

naga = (30 * H) + (M / 2)
mizi = 6 * M

if naga < mizi:
  deg = mizi - naga
elif naga >= mizi:
  deg = naga - mizi
if deg >= 180:
  deg = 360 - deg

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

s = s**(1/2)
print('{:.20f}'.format(s))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
t=h*60+m
short=float(t/2%360)
longer=float(t*6%360)


angle=(abs(short-longer))

if angle >=float(180):
  angles =float(360)-angle
  
  length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angles)))

else:
  length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(angle)))

print('{:.10f}'.format(length))

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

short_time = (h * (360 / 12) + m * 0.5)
long_time = m * (360 / 60)


kakudo = abs(long_time - short_time)

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

Solution (Python):
A,B,H,M = map(int,input().split(' '))
import math
pi = math.pi
sec = M*60
Ht = pi/6*H + pi/360*M
Mt = M * pi/30
cos = abs(Mt-Ht)
ans = math.sqrt(A*A - 2*A*B*math.cos(cos) + B*B)
print(ans)

Solution (Python):
import math

def test(a, b, h, m):
  h_x = a * math.sin(((h * math.pi) / 6) + ((m * math.pi) / 360))
  h_y = a * math.cos(((h * math.pi) / 6) + ((m * math.pi) / 360))
  m_x = b * math.sin((m * math.pi) / 30)
  m_y = b * math.cos((m * math.pi) / 30)
  
  print(math.sqrt(((h_x-m_x) ** 2) + ((h_y-m_y) ** 2)))
  
a, b, h, m = input().split()
test(float(a), float(b), float(h), float(m))

Solution (Python):

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

md = m // 5
md_min = m % 5
th = abs((30 * h + 0.5 * m) - (m * 6))

theta = min(th, 360 - th)

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

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

y = 360/720
z = 360/60

hm = h*60+m

yr = y*hm
zr = z*hm

yrd = (yr-(360*(yr//360)))
zrd = (zr-(360*(zr//360)))

mid = min(yrd,zrd)
mad = max(yrd,zrd)

one = mad-mid
two = 360-one

dg = min(one,two)

cosdg = math.cos(math.radians(dg))

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

print(ans)

Solution (Python):
import numpy as np
import math
A, B, H, M = map(int, input().split())
T = 60 * H + M
rad_A = T / 2
rad_B = M * 6
rad = abs(rad_A - rad_B)
if rad > 180:
  rad = 360 - rad
length = np.sqrt(A*A + B*B - 2*A*B*np.cos(math.radians(rad)))
print(length)

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


def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def solve(a,b,c,d):
    angle = abs(0.5 * (60 * c + d) - 6 * d)
    distance = math.sqrt(pow(a,2) + pow(b,2) - (2*a*b*math.cos(math.radians(angle))))
    return distance

def main():
    a,b,c,d = invr()
    print(solve(a,b,c,d))

main()

Solution (Python):
import math
a,b,h,m = map(int,input().split())
ra = h * 30 + m * 0.5
rb = m * 6
r = math.radians(abs(ra-rb))

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

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

ji = (h * 60 + m) * 0.5
fun = m * 6
ka = abs(ji - fun)
if ka > 180:
    ka = 360 - ka

if ka == 90:
    cc = a ** 2 + b ** 2
else:
    cc = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ka))

c = math.sqrt(cc)

print(c)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
theta1 = (60*h + m) / 2.0;
theta2 = 6.0 * m;
theta = abs(theta1 - theta2);
if theta > 180:
    theta = 360 - theta;
    
c = math.cos(theta / 180 * math.acos(-1));
ans = a*a + b*b - 2*a*b*c;
    
ans = math.sqrt(ans);
print(ans);

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

h = 30*(M/60) + 30 * H
m = 360 * (M/60)
w = abs(h - m) if h > m else abs(m - h)
w = 360 - w if w > 180 else w
a = A
b = B


if w == 180:
    print(A+B)
else:
    w = math.radians(w)
    tmp = math.pow(a - b * math.cos(w), 2) + math.pow(b * math.sin(w), 2)
    c = math.sqrt(tmp)
    print(c)

Solution (Python):
import sys
from collections import deque
import copy
import numpy as np
import math
def main():
    A, B, H, M = map(int, input().split())
    short = H * (360 / 12) + M * 1 / 2
    long_ = M * (360 / 60)
    ang = abs(long_ - short)
    ang = min(ang, 360 - ang)
    a = math.radians(ang)
    h = A * math.sin(a)
    w = B - A * math.cos(a)
    ans = math.sqrt(h ** 2 + w ** 2)
    print(ans)
    
    


if __name__ == '__main__':
    main()

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

for i in range(10):
    if 0<=abs(360*i-abs(30*H+(M/2)-6*M))<360:
        a=abs(360*i-abs(30*H+(M/2)-6*M))
        c=abs(360-abs(360*i-abs(30*H+(M/2)-6*M)))
        break
b=min(a,c)

print("{:.9f}".format(((A**2+B**2-2*A*B*(math.cos(b*(math.pi/180))))**(1/2))))