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())
theta = (360*(h+m/60)/12 - 360*m//60) % 360
theta = theta if theta<=180 else 360-theta
theta = theta * math.pi /180
ans = (a**2+b**2-2*a*b*math.cos(theta))**0.5
print(ans)

Solution (Python):
import math



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

angle_h = h * 30 + m * 0.5
angle_m = m * 6

cos_ = math.cos( math.radians( abs( angle_h - angle_m ) ) )

x = ( a**2 + b**2 - 2*a*b*cos_ ) ** 0.5

print(x)

Solution (Python):
def main():
    from math import pi,e
    A,B,H,M=map(int,input().split())
    J=1j*pi/6
    print(abs(A*e**((H+M/60)*J)-B*e**(M/5*J)))
main()

Solution (Python):
import math

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

degree = abs((H * 60 + M) / 2 - M * 6)

d = A**2 + B**2 - 2 * A * B * math.cos(math.radians(degree))
ans = d**0.5

print(ans)

Solution (Python):
def main():
    from math import pi,e
    A,B,H,M=map(int,input().split())
    J=pi/6j
    print(abs(A*e**((H+M/60)*J)-B*e**(M/5*J)))
main()

Solution (Python):
import cmath
a,b,h,m = map(int, input().split())
h = (h+m/60)*2*cmath.pi/12
m *= 2*cmath.pi/60
a *= cmath.rect(1,h)
b *= cmath.rect(1,m)
print(abs(a-b))

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

long_deg=30*h+30*(m/60)
min_deg=6*m

deg=abs(long_deg-min_deg)

import math

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

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

Solution (Python):
import cmath
a,b,h,m = map(int, input().split())
pi = cmath.pi
h += m/60
h *= 2*pi/12
m *= 2*pi/60
a *= cmath.rect(1,h)
b *= cmath.rect(1,m)
print(abs(a-b))

Solution (Python):
import numpy as np
import cmath
a,b,h,m = map(int, input().split())
pi = np.pi
h += m/60
h *= 2*pi/12
m *= 2*pi/60
a *= cmath.rect(1,h)
b *= cmath.rect(1,m)
print(abs(a-b))

Solution (Python):
from math import *
A,B,H,M=map(int,input().split())
j=pi/6j
print(abs(A*e**((H+M/60)*j)-B*e**(M/5*j)))

Solution (Python):
import math

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

h_rad = math.radians((H * 60 + M) / 2)
m_rad = math.radians(M * 6)

hx, hy = (A * math.sin(h_rad), A * math.cos(h_rad))
mx, my = (B * math.sin(m_rad), B * math.cos(m_rad))

d = ((hx - mx)**2 + (hy - my)**2)**0.5

print(d)

Solution (Python):
import sys
import math
import itertools
import collections

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

if __name__ == "__main__":
    main()

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)


import math


a,b,h,m=n1()

m1=m*360/60
h1=(60*h+m)*360/(12*60)

hx=a*math.sin(math.radians(h1))
hy=a*math.cos(math.radians(h1))
mx=b*math.sin(math.radians(m1))
my=b*math.cos(math.radians(m1))

ans=math.dist([mx,my],[hx,hy])
print(ans)

Solution (Python):
from math import e,pi
A,B,H,M=map(int,input().split())
j=pi/6j
print(abs(A*e**((H+M/60)*j)-B*e**(M/5*j)))

Solution (Python):
from collections import defaultdict as dd
import math

def ri():
    return int(input())

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

def rl2():
    return list(rl())

A, B, H, M = rl()
minutes = 60 * H + M
full1 = 60 * 12
full2 = 60

theta1 = 2 * math.pi * (minutes / full1)
theta2 = 2 * math.pi * (minutes / full2)

x1, y1 = A * math.cos(theta1), A * math.sin(theta1)
x2, y2 = B * math.cos(theta2), B * math.sin(theta2)

d = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
print (d)

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

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

xa = A * math.sin(H * math.pi / 6 + M * math.pi / 360)
ya = A * math.cos(H * math.pi / 6 + M * math.pi / 360)
xb = B * math.sin(M * math.pi / 30)
yb = B * math.cos(M * math.pi / 30)

l = math.sqrt((xb - xa) ** 2 + (yb - ya) ** 2)
print(l)

Solution (Python):
def main():
    from math import e, pi
    A,B,H,M = map(int,input().split())
    
    
    argA = (H + M/60)/12*2*pi 
    argB = M/60*2*pi
    pA = A*pow(e,complex(0,argA))
    pB = B*pow(e,complex(0,argB))
    print(abs(pA - pB))
main()

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

angle_b=360*m/60
angle_a=360*(total_m/(12*60))

angle=min(abs(angle_a-angle_b),360-abs(angle_a-angle_b))
cosθ=math.cos(math.radians(angle))

c=(a**2+b**2-2*a*b*cosθ)
c=c**(1/2)
print(c)

Solution (Python):
a,b,h,m = map(int, input().split())
import math
a_x = a * math.cos(math.radians(30*h + 0.5*m))
a_y = a * math.sin(math.radians(30*h + 0.5*m))
b_x = b * math.cos(math.radians(6*m))
b_y = b * math.sin(math.radians(6*m))

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

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


import math

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

angle = abs(h*30 + m/2 - m*6)
angle = min(angle, 360 - angle)

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

Solution (Python):
import math as m
A,B,H,M = map(int,input().split())
hour_angle =(30*H+0.5*M)
minute_angle =(6*M)
hour_X = float('{:.12f}'.format(m.sin(m.radians(hour_angle))))*A
hour_Y = float('{:.12f}'.format(m.cos(m.radians(hour_angle))))*A
minute_X = float('{:.12f}'.format(m.sin(m.radians(minute_angle))))*B
minute_Y = float('{:.12f}'.format(m.cos(m.radians(minute_angle))))*B

print(m.sqrt((hour_X-minute_X)**2+(hour_Y-minute_Y)**2))

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

y = (30.*H + 0.5*M) - 6.*M
y = y*math.pi/180.
y = math.cos(y)
x = math.sqrt(A**2. + B**2. - 2.*A*B*y)

print(x)

Solution (Python):
from decimal import *
def calc(l,theta):
    tmpcos = Decimal(math.cos(theta))
    tmpsin = Decimal(math.sin(theta))

    return l*tmpsin,l*tmpcos

import math
a,b,h,m = map(int,input().split())
thetaA = Decimal(((60*h+m)/720)*(2*math.pi))
x1,y1 = calc(a,thetaA)
thetaB =  Decimal(2*(math.pi)*(m/60))
x2,y2 = calc(b,thetaB)
ans = Decimal((x1-x2)**2 + (y1-y2)**2)
ans = Decimal(math.sqrt(ans))

print(ans)

Solution (Python):
import math
A, B, H, M = map(float, input().split())
long_deg = M*6
short_deg = M/2+H*30
rad = (long_deg - short_deg)*2*math.pi/360
print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad)))

Solution (Python):
from math import radians
from cmath import exp

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




hdeg = radians(h * 30 + m * 0.5)
mdeg = radians(m * 6)


hz = a * exp(complex(0, hdeg))
mz = b * exp(complex(0, mdeg))


dist = abs(hz - mz)

print(dist)

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

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




hdeg = radians(h * 30 + m * 0.5)
mdeg = radians(m * 6)


hz = a * exp(complex(0, hdeg))
mz = b * exp(complex(0, mdeg))


dist = abs(hz - mz)

print(dist)

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

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




hdeg = radians(h * 30 + m * 0.5)
mdeg = radians(m * 6)


hz = a * exp(complex(0, hdeg))
mz = b * exp(complex(0, mdeg))


dist = abs(hz - mz)

print(dist)

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

h_deg = h*30 + m*0.5  

m_deg = m*6 
h_rad = radians(h_deg)
m_rad = radians(m_deg)
ax = a*cos(h_rad)
ay = a*sin(h_rad)
bx = b*cos(m_rad)
by = b*sin(m_rad)
c2 = (ax-bx)**2 + (ay-by)**2
print(sqrt(c2))

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

x = 30*h + (m/60)*30 
y = 6*m 
z = abs(x-y)

print((a**2+b**2-2*a*b*math.cos(math.radians(z)))**0.5)

Solution (Python):
import math

A,B,H,M = map(float, input().split())
pi = math.pi
Ak = 360*H/12+360/12*M/60
Bk = 360*M/60
Ak = Ak/180*pi
Bk = Bk/180*pi


ans = A*A+B*B-2*A*B*math.cos(Ak-Bk)
print(math.sqrt(ans))

Solution (Python):
a,b,h,m = map(int, input().split())
import math
a_x = a * math.cos(math.radians(30*h + 0.5*m))
a_y = a * math.sin(math.radians(30*h + 0.5*m))
b_x = b * math.cos(math.radians(6*m))
b_y = b * math.sin(math.radians(6*m))

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

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(C)))
print(total)

Solution (Python):
import numpy as np


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

h_dig = 360 // 12 * (h + m / 60)
m_dig = 360 // 60 * m
dig1 = abs(h_dig-m_dig) 
dig2 = 360 - dig1

rad = max(np.cos(np.deg2rad(dig1)), np.cos(np.deg2rad(dig2)))
print(np.sqrt(a ** 2 + b ** 2 - (2 * a * b * rad)))

Solution (Python):
a,b,h,m = map(int, input().split())
import math
a_x = a * math.cos(math.radians(30*h + 0.5*m))
a_y = a * math.sin(math.radians(30*h + 0.5*m))
b_x = b * math.cos(math.radians(6*m))
b_y = b * math.sin(math.radians(6*m))

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

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

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

theta = min(theta, 360-theta)

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

print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


a, b, h, m = LI()
i = (h / 12  + m / 720) * 2 * pi
j = m / 60 * 2 * pi
print((a ** 2 + b ** 2 - 2 * a * b * cos(i - j)) ** 0.5)

Solution (Python):
import math

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

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

rad = math.radians(x)

ans_pow = a * a + b * b - 2 * a * b * math.cos(rad)

print(math.sqrt(ans_pow))

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

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

import math

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

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

    rad = math.radians(x)

    ans_pow = a * a + b * b - 2 * a * b * math.cos(rad)

    print(math.sqrt(ans_pow))

if __name__ == '__main__':
    main()

Solution (Python):
import math

def main():
    a, b, h, m = input_list()
    ang = get_angle(h, m)
    coss = math.cos((ang/180)*math.pi)
    ans = math.sqrt(a**2 + b**2 - 2*a*b*coss)
    print(ans)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

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


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, stdout
from collections import deque, defaultdict
from math import cos, sin, sqrt, pi

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	a, b, h, m = rli()
	mins = 60*h + m
	hcoor = lambda t: (a*cos(2*pi*t/720), a*sin(2*pi*t/720))
	mcoor = lambda t:(b*cos(2*pi*t/60), b*sin(2*pi*t/60))
	dist = lambda x1, y1, x2, y2: sqrt((x1-x2)**2 + (y1-y2)**2)
	x1, y1 = hcoor(mins)
	x2, y2 = mcoor(m)
	print(dist(x1, y1, x2, y2))
	stdout.close()

if __name__ == "__main__":
	main()

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

Solution (Python):
from math import pi
from cmath import rect

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

thetaA = (H / 12) + (M / 60) * (1 / 12)
thetaB = (M / 60)

thetaA *= 2 * pi
thetaB *= 2 * pi

P = rect(A, thetaA)
Q = rect(B, thetaB)

print(abs(P - Q))

Solution (Python):
import math


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


x = 360 * (H * 60 + M) / (12 * 60)

y = 360 * M / 60

radians = math.radians(abs(x - y))

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

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

rad = math.pi * 2 * (h/12.0 + m/60.0 / 12.0 - m/60.0)
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad))
print(ans)

Solution (Python):
import numpy as np
a,b,h,m = [int(i) for i in input().split()]

theta = 5.5 * (60*h + m) % 360

ans = a**2 + b**2 - 2 * a * b * np.cos(np.deg2rad(theta))

print(np.sqrt(ans))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
time = h + m/60
theta = abs(6*m - 30 * time%360)*math.pi/180
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())
cho = 6 * M
tan = 30 * H
gap = 0.5 * M
kakudo = tan + gap - cho
if kakudo == 180:
    print(A+B)
    exit()
if kakudo > 180:
    kakudo = 360 - kakudo
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(kakudo))
print(ans ** 0.5)

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

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

arc_h = 2 * math.pi * ((h + m / 60) / 12)
arc_m = 2 * math.pi * (m/60)
dx = a * math.cos(arc_h) - b * math.cos(arc_m)
dy = a * math.sin(arc_h) - b * math.sin(arc_m)
d = math.sqrt(dx ** 2 + dy ** 2)
print(d)

Solution (Python):
import math
 
def dcos(x):
    return math.cos(math.radians(x))
 
A, B, H, M = map(int, input().split())
 
one_H = 360 / 12
one_M = 360 / 60
one_H_M = one_H / 60
 

kakudo_H = one_H * H

kakudo_H = kakudo_H + one_H_M*M
 


 
kakudo_M = one_M * M


 
kakudo = abs(kakudo_M - kakudo_H)
if kakudo > 180:
    kakudo = 360 - kakudo

ans = A**2 + B**2 + (-2)*A*B*dcos(kakudo)
 
print(ans**0.5)

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
import math
def main():
    a,b,h,m=map(int,input().split())
    theta_a=(60*h+m)*2*math.pi/720
    theta_b=m*2*math.pi/60
    print(math.sqrt((a*math.cos(theta_a)-b*math.cos(theta_b))**2+(a*math.sin(theta_a)-b*math.sin(theta_b))**2))

if __name__=='__main__':
    main()

Solution (Python):
import math
 
def dcos(x):
    return math.cos(math.radians(x))
 
A, B, H, M = map(int, input().split())
 
one_H = 360 / 12
one_M = 360 / 60
one_H_M = one_H / 60
 

kakudo_H = one_H * H

kakudo_H = kakudo_H + one_H_M*M
 


 
kakudo_M = one_M * M


 
kakudo = abs(kakudo_M - kakudo_H)

ans = A**2 + B**2 + (-2)*A*B*dcos(kakudo)
 
print(ans**0.5)

Solution (Python):
import math

a,b,c,d = map(int,input().split())
ans = 0.0

e1 = (2 * math.pi) / 12
e2 = (2 * math.pi) / 60
e3 = (2 * math.pi) / (60 * 12)

a2 = c * e1 + d * e3
b2 = e2 * d


dif = abs(a2-b2)

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


print(ans)

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

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

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



  
angle_h = (h*60 + m) * (360 / 12 / 60)
angle_m = m * (360 / 60)
 
angle = abs(angle_h - angle_m)
radian = math.radians(angle)
cosine = math.cos(radian)
ans = a*a + b*b - 2*a*b * cosine
ans = math.sqrt(ans)
 
print(ans)

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * (360 / (60 * 12))
deg_b = m * (360 / 60)
deg = abs(deg_a - deg_b)
rad = math.radians(deg)

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

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

h = h + m/60

rotH = (360 * h/12 ) % 360
rotM = (360 * h ) % 360


totalRot = abs(rotM - rotH)


cosineR = math.sqrt(a**2 + b**2 - 2*(a*b*math.cos(math.radians(totalRot))))

print(cosineR)

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

long = 6 * M

short = 30*(H) + 0.5*M
theta = abs(long - short)
if theta > 180:
    theta = 360 - theta
cos = math.cos(math.radians(theta))
x = A**2 + B**2 - 2*A*B*cos
x = math.sqrt(x) 
n = 10 
y = Decimal(str(x)).quantize(Decimal(str(10**(n*-1))), rounding=ROUND_DOWN)
print(y)

Solution (Python):
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

import math

def main():
    a, b, h, m = map(int, input().split())
    p = 30 * (h + m / 60)
    q = 6 * m
    r = abs(p - q)
    if r > 180:
        r = 360 - r
    r = math.radians(r)
    ans = ((a - b * math.cos(r)) ** 2 + (b * math.sin(r)) ** 2) ** (1 / 2)
    print('{:.9f}'.format(ans))
main()

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

n%=12
n*=30
m*=6
n+=m/60*5
ans=abs(n-m)
if ans>180:
    ans=360-ans

print(math.sqrt(a*a+b*b-2*a*b*math.cos(ans*math.pi/180)))

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

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

thetaA = (H / 12) + (M / 60) * (1 / 12)
thetaB = (M / 60)

thetaA *= 2 * PI
thetaB *= 2 * PI

P = complex(A * cos(thetaA), A * sin(thetaA))
Q = complex(B * cos(thetaB), B * sin(thetaB))

print(abs(P - Q))

Solution (Python):
import math

a,b,h,m = map(int,input().split())
if h ==0:
    h=12
mi=m
if m==0:
    mi=60

tns = a*(math.sin((2*math.pi/720)*(h*60+m)))
tnc = a*(math.cos((2*math.pi/720)*(h*60+m)))
tys = b*(math.sin((2*math.pi/60)*mi))
tyc = b*(math.cos((2*math.pi/60)*mi))

print(math.sqrt((tns-tys)**2+(tnc-tyc)**2))

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

Solution (Python):
import math

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

c = abs(H*30+M/2-M*6)

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

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

Solution (Python):
import numpy as np
import math

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

h_a = (h + m/60) * 30
m_a = m * 6
angle = abs(h_a - m_a)
if angle > 180:
    angle = 360 - angle

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

print(ans)

Solution (Python):
import math
 
a,b,h,m = (int(x) for x in input().split())
dh = 30*h+0.5*m
dm = 6*m
if dh==dm:
  print(abs(a-b))
elif dh<dm:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dm-dh))))
else:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dh-dm))))

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



input = input().split()

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

rad = 2*pi*(H/12.0+(M/60.0)/12.0-M/60.0)
out = sqrt((pow(A,2)+pow(B,2))-(2*A*B*cos(rad)))

print(out)

Solution (Python):
import math

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

aa=30*h+m/2
bb=6*m
t=aa-bb
ans=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(t)))
print(ans)

Solution (Python):
import math

a,b,h,m = (int(x) for x in input().split())
dh = 30*h+0.5*m
dm = 6*m
if dh==dm:
  print(abs(a-b))
elif dh<dm:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dm-dh))))
else:
  print(math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(dh-dm))))

Solution (Python):
import math

PI = math.pi

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

rad = 2 * PI * abs(h / 12.0 + m / 60.0 / 12.0 - m / 60.0)

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

print(ans)

Solution (Python):
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

from math import cos, sin, radians

a,b,h,m = (int(x) for x in input().split())
t1 = radians(((h%12) * 30) + m*0.5)
t2 = radians(((m%60) * 6))

x1 = -a*sin(-t1)
y1 = a*cos(-t1)
x2 = -b*sin(-t2)
y2 = b*cos(-t2)
print(((x2-x1)**2+(y2-y1)**2)**0.5)

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

angleMin = (m/60) * 2 * pi
angleMax = ((60*h+m)/(60*12)) * 2 * pi

diff = min(abs(angleMax-angleMin), 2*pi-abs(angleMax-angleMin))

dist = sqrt(a**2 + b**2 - 2*a*b*cos(diff))
print(dist)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
h_v = (h + m/60)* 30
m_v = m * 6
k = abs(h_v-m_v)
if k > 180:
	k = 360 - k
r = 0
if k == 0:
	r = a - b
else:
	radian = math.radians(k)
	r2 = a**2 + b**2 - (2 * a * b * math.cos(radian))
	r = r2**0.5
print(r)

Solution (Python):
import math

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

H %= 12
M %= 60

hour = (H + M / 60) * 30
mins = M * 6

angle = abs(hour - mins)

angle = min(360 - angle, angle)

angle = math.radians(angle)

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

Solution (Python):

from math import cos, radians, sqrt


def main():
    A, B, H, M = map(int, input().split())
    rad = abs(H * 30 - M * 5.5)
    ans = sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(radians(rad)))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math

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

U=(M/60)*2*math.pi
V=(H*60+M)/(12*60)*2*math.pi
W=abs(U-V)

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

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

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

aug = 6*d - (30*c + (30*(d/60)))

if aug == 0:
    len = a - b
else:
    len = a**2 + b**2 - (2 * a* b *(math.cos(math.radians(aug))))
    len = len**0.5

print(len)

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

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

t1 = (H * 360 / 12) + (M * (360/12) / 60)
t2 = (M * 360 / 60)

theta1 = max(t1, t2) - min(t1, t2)
theta2 = 360 + min(t1, t2) - max(t1, t2)
theta = math.radians(min(theta1, theta2))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)))

Solution (Python):


ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

from math import sqrt,cos,pi
a,b,h,m = ip()
angle = abs((h*60 + m)/2 - 6*m)
angle = min(360-angle,angle)*pi/180
c = sqrt(a**2 + b**2 - 2*a*b*cos(angle))
print(c)

Solution (Python):
from math import cos, sin, sqrt, radians
short, long, hour,minit = map(int,input().split())

short_kaku = 90 - (30 * hour + 0.5 * minit)
short_x = short * cos(radians(short_kaku))
short_y = short * sin(radians(short_kaku))

long_kaku = 90 - 6 * minit
long_x = long * cos(radians(long_kaku))
long_y = long * sin(radians(long_kaku))

distance = sqrt((short_x - long_x) ** 2 + (short_y - long_y) ** 2)

print(distance)

Solution (Python):
import numpy as np
import math


def get_calc_vec(base, a):
    rad = math.radians(a)
    x = np.array([[math.cos(rad), -math.sin(rad)],
                  [math.sin(rad), math.cos(rad)]])
    ans = np.dot(x, base)
    return ans


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

    
    a_H = sum_time / 720 * 360
    a_M = M / 60 * 360
    

    base_H_vec = np.array([0, A])
    base_M_vec = np.array([0, B])
    
    vec_H = get_calc_vec(base_H_vec, a_H)
    vec_M = get_calc_vec(base_M_vec, a_M)

    ans_vec = vec_H - vec_M
    print(np.linalg.norm(ans_vec, ord=2))


main()

Solution (Python):
import math

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

x = math.cos(M * math.pi / 30 - (H * math.pi / 6 + M * math.pi / 360))

ans = A*A + B*B -2 * A * B * x
print(math.sqrt(ans))

Solution (Python):
import math
inputs = input().split()
A, B, H, M = int(inputs[0]), int(inputs[1]), int(inputs[2]), int(inputs[3])
num_diff = H*5+M/12 - M

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

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

ha = 30*h + 0.5*m
ma = 6*m
ang = ha - ma

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

A_angle = (H*60+M)*0.5
B_angle = M*6


angle = abs(A_angle - B_angle)


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

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

Solution (Python):
import math


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

minutes = h * 60 + m

min_needle_angle = minutes * 6
hour_needle_angle = minutes * 0.5


if min_needle_angle > 360:
    min_needle_angle %= 360 

angle = max(min_needle_angle, hour_needle_angle) - min(min_needle_angle, hour_needle_angle)







angle = min(angle, 360 - angle) 












c_nijou =  a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle))

print((c_nijou)**0.5)

Solution (Python):
import cmath

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

A = param[0]
B = param[1]
h = param[2]
m = param[3]

v = (A*pow(cmath.e, (cmath.pi*m/30)*1j) - B*pow(cmath.e, (cmath.pi*h/6 + cmath.pi*m/360)*1j))

print(abs(v))

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


ha = 6 * (5 * H + (M/60 * 5))
ma = 6 * M
angle = min(360 - abs(ha - ma), abs(ha - ma))

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

Solution (Python):
import math
A,B,H,M = (int(x) for x in input().split())
arg = (math.pi*H/6 + math.pi*M/360) - math.pi*M/30
if (arg < 0):
  arg = -arg
s = A**2 + B**2 - 2*A*B*math.cos(arg)
print(math.sqrt(s))

Solution (Python):
import math

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

Solution (Python):
import math
def calc(h,m): 
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
    return angle 

a,b,h,m = map(int,input().split())
angle = calc(h,m)
ag = math.radians(angle)
c = a**2 +b**2 - (2*a*b*math.cos(ag))
print(math.sqrt(c))

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

Solution (Python):
import math
b, c, h, m = input().split()
b = int(b)
c = int(c)
h = int(h) + int(m) / 60
m = int(m) / 5
num = 0
a = 0

if abs(h - m) > 6:
    if h > m:
        h = h - 12
    else:
        m = m - 12
if h - m ==6:
    a = b + c
    print(a)
else:
    num = abs(h - m)
    radian = 30 * num
    a = math.sqrt(b**2 + c**2 - 2 * b * c * math.cos(math.radians(radian)))
    print(a)

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


hsita = 30 * h + 0.5*m
msita = 6 * m


hx = math.cos(math.radians(hsita)) * a
hy = math.sin(math.radians(hsita)) * a
mx = math.cos(math.radians(msita)) * b
my = math.sin(math.radians(msita)) * b


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

print(ans)

Solution (Python):
import math


def main():
    a, b, h, m = map(int, input().split())
    th = (h * 60 + m) / 720 * 2 * math.pi
    tm = m / 60 * 2 * math.pi
    xh = a * math.cos(th)
    yh = a * math.sin(th)
    xm = b * math.cos(tm)
    ym = b * math.sin(tm)
    dx = xh - xm
    dy = yh - ym
    ans = math.sqrt(dx ** 2 + dy ** 2)
    print("%.10f" % ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,h,m = MAP()

angle = 5.5*m - h*30

if(angle<0):
    angle+=360

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

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

h_deg = h*30 + m*0.5  

m_deg = m*6 
deg = h_deg - m_deg
rad = math.radians(deg)
c2 = a**2 + b**2 - 2*a*b*math.cos(rad)
print(math.sqrt(c2))