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

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

A_zahyou = [A * math.sin(math.radians(A_theta)) , A * math.cos(math.radians(A_theta)) ]
B_zahyou = [B * math.sin(math.radians(B_theta)) , B * math.cos(math.radians(B_theta)) ]


dist_2 = (A_zahyou[0] - B_zahyou[0]) ** 2 + (A_zahyou[1] - B_zahyou[1]) ** 2
dist = math.sqrt(dist_2)
print(dist)

Solution (Python):
import math

A,B,H,M = list(map(int,input().split()))
H_deg = 30*H+0.5*M
M_deg = 6*M
x1 = A*math.cos(math.radians(H_deg))
y1 = A*math.sin(math.radians(H_deg))
x2 = B*math.cos(math.radians(M_deg))
y2 = B*math.sin(math.radians(M_deg))
print(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2))

Solution (Python):


import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
a, b, h, m = map(int, input().split())
theta = abs(h * 30 + m * 0.5 - (6 * m))

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

Solution (Python):
import math
j,f,h,m=map(int,input().split())
df=6*m
dh=m/2+30*h
d=0
if df>dh:
  d=df-dh
else:
  d=dh-df
l=(j**2+f**2-2*j*f*math.cos(math.radians(d)))**0.5
print(l)

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

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

bt=m*pi/30
at=h*pi/6+m*pi/360
t=abs(at-bt)
ans=(a*a+b*b-2*a*b*math.cos(t))**0.5

print(ans)

Solution (Python):
import numpy as np

a, b, h, m = map(int, input().split())
theta = np.pi / 6 * (h + m / 60)
phi = np.pi / 30 * m
ans = np.sqrt((a * np.sin(theta) - b * np.sin(phi))**2 + (a * np.cos(theta) - b * np.cos(phi))**2)
print(ans)

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

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

Solution (Python):
def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

import math
a,b,h,m = mp()
hkaku = h*30+m*0.5
mkaku = m*6
cos = math.cos((mkaku-hkaku)*math.pi/180)
u = a**2+b**2-2*a*b*cos
print(math.sqrt(u))

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

a = 30*H + M/2
b = 6*M
theta = math.radians(b-a)
x_2 = A*A + B*B - 2*A*B*math.cos(theta)
print(x_2 ** 0.5)

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

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

minutes_in_hour = 60
minutes_in_12h = 12*60

mins = 60*h + m

ang_hour = 360 * mins / minutes_in_12h
ang_min = 360 * m / minutes_in_hour

ang_betw = radians( (ang_hour - ang_min + 360) % 360)

c = sqrt(a*a + b*b - 2 * b *a * cos(ang_betw))
print(c)

Solution (Python):



def get_clock_distance(A, B, H, M):
    import math
    angle = min(abs(30 * H + 0.5 * M - 6 * M), abs(360 - (30 * H + 0.5 * M - 6 * M)))
    return (A**2 + B**2 - 2 * A * B * math.cos(math.radians(angle)))**0.5

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

if __name__ == "__main__":
    main()

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

Solution (Python):
import math

if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    ar =  30 * a[2] + (a[3] /2)
    br = 6 *a[3]

    ax = a[0]* math.sin(math.radians(ar))
    ay = a[0]* math.cos(math.radians(ar))
    bx = a[1]* math.sin(math.radians(br))
    by = a[1]* math.cos(math.radians(br))

    length = abs(ax-bx)*abs(ax-bx)+abs(ay-by)*abs(ay-by)

    print(math.sqrt(length))

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
from collections import deque
import heapq
from itertools import combinations
import bisect


import math

a,b,h,m=map(int,input().split())
aa=(h+m/60.0)*30.0
bb=m*6
t=aa-bb

ans=(a*a+b*b-2*a*b*math.cos(t*math.pi/180.0))**0.5
print(ans)

Solution (Python):

import math

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

A_ratio = (60*H+M)/720
B_ratio = M/60

sa = abs(A_ratio - B_ratio)

theta = min(2*math.pi*sa, 2*math.pi*(1-sa))

C = math.sqrt(pow(A,2)+pow(B,2) - (2*A*B*math.cos(theta)))

print(C)

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

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

ta = h * pi/6 + m * pi/360
tb = m * pi/30
t = abs(ta - tb)

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

Solution (Python):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

a, b, h, m = MAP()
sheta = abs(math.radians(((60*h+m)/2)-6*m))
print(math.sqrt(a**2 + b**2 -2*a*b*math.cos(min(sheta, math.pi*2-sheta))))

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

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


A_angle=(H+M/60)/12*360
B_angle=(M/60)*360


max_angle=max(A_angle,B_angle)
min_angle=min(A_angle,B_angle)

diff = max_angle-min_angle


rad = diff*pi/180

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

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

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

a=2*pi*(h/12+m/720)
b=2*pi*(m/60)
t=a-b

l=sqrt(A*A+B*B-2*A*B*cos(t))

print(l)

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


if abs(30*H-5.5*M)%360<=180:
    theta=abs(30*H-5.5*M)%360*math.pi/180
else:
    theta=(360-abs(30*H-5.5*M)%360)*math.pi/180

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

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

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

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

tyo=(2*math.pi/60)*fun
tan=(math.pi/360)*fun
tyoo=tyo//(2*math.pi)
tyo=tyo-2*math.pi*tyoo

theta=abs(tyo-tan)
ans=math.sqrt(a**2+b**2-2*a*b*math.cos(theta))

print(ans)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
A, B, H, M = map(int, input().split())
if H > 12:
    H -= 12
p = np.pi
min_ang = 2 * p * (M / 60)
hour_ang = 2 * p * (H / 12)
hour_ang += (1 / 6) * p * (M / 60)

mid = abs(hour_ang - min_ang)
mid = min(mid, 2 * p - mid)

ans = A ** 2 - 2 * A * B * np.cos(mid) + B ** 2
print(ans ** .5)

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

ji=(h*60+m)/2
hun=6*m
theta=min(abs(ji-hun),360-abs(ji-hun))
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(theta)))
print(c)

Solution (Python):
import math

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

def rorate(x, y, theta):
    nx = x * math.cos(theta) - y * math.sin(theta)
    ny = x * math.sin(theta) + y * math.cos(theta)
    return nx, ny

hun = math.pi * M / 30
zi = math.pi * (30 * H + (M / 2)) / 180

na = rorate(0, A, zi)
nb = rorate(0, B, hun)

print(math.sqrt((na[0] - nb[0]) ** 2 + (na[1] - nb[1]) ** 2))

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

a, b, h, m = map(int, input().split())
th = (60 * h + m) * 360 / 720
tm = m * 360 / 60
print(sqrt(a**2 + b**2 - 2 * a * b * cos(pi * (th - tm) / 180)))

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


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

    short = (H % 12) * 30 + float(M) / 60.0 * 30.0
    lon = M / 60 * 360
    angle = abs(short-lon)
    if angle <= 180:
        pass
    else:
        angle = 360 - angle

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from math import cos,sqrt,radians
a,b,h,m = [int(i) for i in input().split()]
br = 6*m
ar = 30*h + m/2
th = abs(ar-br)
th = radians(min(th,360-th))
ansj = a**2 + b**2 - 2*a*b*cos(th)
print(sqrt(ansj))

Solution (Python):
import math

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

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

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

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

theta1 = 2 * pi / 12  
theta2 = theta1 / 60  
theta3 = 2 * pi / 60
angle_H = H * theta1 + M * theta2
angle_M = M * theta3
angle = angle_H - angle_M
l = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle))
print(l)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
rad = abs(6.0 * m -30 * h -0.5 * m)
rad = min(360-rad,rad)
print(math.sqrt(a**2 + b ** 2 -2 * a * b * math.cos((rad/180) * math.pi)))

Solution (Python):
import math

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

h_angle = (60*h+m)/2
m_angle = 6*m
angle = abs(h_angle - m_angle)


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

Solution (Python):
def main():
    import sys
    import math
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    A, B, H, M = [int(x) for x in input().strip().split()]
    hours = 2 * math.pi * (60 * H + M) / (60 * 12)
    minites = 2 * math.pi * M / 60
    Ax, Ay = A * math.sin(hours), A * math.cos(hours)
    Bx, By = B * math.sin(minites), B * math.cos(minites)
    print(((Ax-Bx)**2+(Ay-By)**2)**.5)
    
if __name__ == '__main__':
    main()

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

totalM = 60*h + m

aDegree = 30 / 60 * totalM

bDegree = 360 / 60 * totalM

import math

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

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

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

Solution (Python):
import math

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


tansin = 360 * h / 12 + 360 * m / 60 / 12
chosin = 360 * m / 60


sa = abs(chosin - tansin)
sa = min(360 - sa, sa)

sa = math.radians(sa)
nijo = a * a + b * b - 2 * a * b * math.cos(sa)
print(nijo ** 0.5)

Solution (Python):
import math

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

x = (60 * h + m) / 720 * 2 * math.pi
y = m / 60 * 2 * math.pi

k = abs(x - y)
if k == math.pi:
    print(a + b)
    exit()
if k > math.pi:
    k = 2 * math.pi - k

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

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

A, B, H, M = rl()


h = H + M/60
t1 = math.pi/6 * h - math.pi/2
x1, y1 = A*math.cos(t1), A*math.sin(t1)

t2 = math.pi/30 * M - math.pi/2
x2, y2 = B*math.cos(t2), B*math.sin(t2)

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

Solution (Python):
import math


def main():
    a, b, h, m = map(int, input().split())
    total_min = h * 60 + m
    ratio = total_min / (12 * 60)

    theta_h = ratio * math.pi * 2
    theta_m = m / 60 * math.pi * 2
    theta = math.fabs(theta_h - theta_m)

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



if __name__=="__main__":
    main()

Solution (Python):
import math
import pprint
import fractions
import collections
import itertools
A,B,H,M=map(int,input().split())
s1=0.5*(60*H+M)
s2=6*M
theta=min(abs(s1-s2),360-abs(s1-s2))

print(math.sqrt(pow(A,2)+pow(B,2)-2*A*B*math.cos(math.radians(theta))))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
kak=abs(6*m-(h+m/60)*30)

kakok=math.radians(kak)

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

Solution (Python):
import math

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

Atheta = (H+M/60)/12*360
Btheta = M/60*360
Ax = A*math.sin(math.radians(Atheta))
Ay = A*math.cos(math.radians(Atheta))
Bx = B*math.sin(math.radians(Btheta))
By = B*math.cos(math.radians(Btheta))

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

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

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

import math
angle_a = 2*math.pi*(H+M/60)/12
angle_b = 2*math.pi*M/60


ax = A*math.cos(angle_a)
ay = A*math.sin(angle_a)
bx = B*math.cos(angle_b)
by = B*math.sin(angle_b)

dx = abs(ax-bx)
dy = abs(ay-by)
ans = math.sqrt(dx**2 + dy**2)
print(ans)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
minutes = m+h*60
longer = 6*minutes % 360
shorter = 0.5*minutes
cosine = math.cos(math.radians(longer-shorter))
print(math.sqrt(a**2+b**2-2*a*b*cosine))

Solution (Python):
import math
A, B, H, M =map(int, input().split())
Min = 60*H + M
long_v = 0.5
short_v = 6
diff = 5.5*Min%360
print((A**2 + B**2 - 2*A*B*math.cos(math.radians(diff)))**0.5)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
ax = A * math.sin(math.radians(30 * H + M / 2))
ay = A * math.cos(math.radians(30 * H + M / 2))
bx = B * math.sin(math.radians(6 * M))
by = B * math.cos(math.radians(6 * M))
ans = ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
print(ans)

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

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

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

hx = 360 * h
mx = 360 * m
dx = min(abs(hx - mx), 360 - abs(hx - mx))
dtheta = math.radians(dx)
ret = (A * math.sin(dtheta)) ** 2 + (B - A * math.cos(dtheta)) ** 2
print(math.sqrt(ret))

Solution (Python):
import math
a,b,h,m = map(int, input().split())
p = (h*60+m)%720/720
q = (h*60+m)%60/60
px,py = a*math.sin(2*math.pi*p),a*math.cos(2*math.pi*p)
qx,qy = b*math.sin(2*math.pi*q),b*math.cos(2*math.pi*q)

print(((qx-px)**2+(qy-py)**2)**0.5)

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


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

h = 2 * pi * (H / 12 + M / 720)
m = 2 * pi * (M / 60)
ax, ay = A * cos(h), A * sin(h)
bx, by = B * cos(m), B * sin(m)
print(sqrt((ax - bx) ** 2 + (ay - by) ** 2))

Solution (Python):
import math
def main():
    a,b, h, m = map(int,input().split())
    l = 360 * (m/60)
    s = 30 * h + 30 * (m/60)
    r = abs(s-l)
    ans = a**2 + b**2 -2*a*b*math.cos(math.radians(r))
    print(ans**0.5)
if __name__=='__main__':
    main()

Solution (Python):
import numpy as np
a,b,h,m = map(int, input().split())
s = 2 * np.pi * (h * 60 + m) / (12 * 60)
t = 2 * np.pi * m / 60
ans = a*a + b*b - 2*a*b * np.cos(min(abs(t-s),abs(s-t)))
print(ans**0.5)

Solution (Python):
import math

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

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


hour_theta = h * 30 + m * 0.5
min_theta = m * 6

if hour_theta - min_theta < 180:
  theta = hour_theta - min_theta
  print(cosine(a, b, theta))
elif hour_theta - min_theta > 180:
  theta = min_theta - hour_theta
  print(cosine(a, b, theta))
else:
  print(a+b)

Solution (Python):
import math

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

r = abs(((h * 60 + m) / 720) - (m / 60))
r = min(1-r, r) * math.pi * 2

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

print(ans)

Solution (Python):
import math

a, b, h, m = map(int, input().split())
deg = 5.5 * (60 * h + m) % 360
rad = deg * (math.pi * 2) / 360
print((a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)) ** 0.5)

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))

def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]

def to_bin(x: int) -> str: return format(x,'b') 
def to_oct(x: int) -> str: return format(x,'o') 
def to_hex(x: int) -> str: return format(x,'x') 
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, n+1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res

MOD=10**9+7

import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
from math import cos, radians

def main():
    a, b, h, m = MII()
    hd = h*30 + 30*(m/60)
    md = 6*m
    d = max(hd, md) - min(hd, md)
    if d > 180:
        d = 360 - d
    cc = a**2 + b**2 - 2*a*b*cos(radians(d))
    print(cc**(1/2))

if __name__ == '__main__':
    main()

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

Solution (Python):
import math
h,m,a,b=map(int,input().split())
if a>=12:
    a-=12
hour=360/12
hour_angle=hour*a+hour/60*b
minute=360/60
minute_angle=minute*b
ans=min(abs(minute_angle-hour_angle),360-abs(minute_angle-hour_angle))
print((h**2+m**2-2*h*m*math.cos(math.radians(ans)))**(1/2))

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

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

m = 60 * h + m
hour = 0.5
minute = 6

c = hour * m % 360
d = minute * m % 360

seta = min(abs(c - d), 360 - abs(d - c))

ans = a ** 2 + b ** 2 - 2 * a * b * cos(radians(seta))
print(ans ** 0.5)

Solution (Python):
a,b,h,m=map(int,input().split())
theta_b=6*m
theta_a=30*h+m/2
import math
theta=(theta_b-theta_a)*math.pi/180
l=((a**2)+(b**2)-2*a*b*math.cos(theta))**(1/2)
print(l)

Solution (Python):
from sys import stdin
import math

def main():

    input = stdin.readline

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

    m_rad = M * 360 / 60

    n_rad = (n_12 * 360 / 12) + (M * 30 / 60)

    radi = abs(m_rad - n_rad) if abs(m_rad - n_rad) < 180 else abs(360 - abs(m_rad - n_rad))

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

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp



class UnionFindEx:
    def __init__(self, size):
        
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    A,B,H,M=mis()
    H = (H*60+M)/(60*12)*2*math.pi
    M = M/60*2*math.pi
    c2 = A**2 + B**2 - 2*A*B*math.cos(H-M)
    print(c2**0.5)

main()

Solution (Python):
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'

    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase

input=lambda: sys.stdin.readline().rstrip()
 
class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
class SparseTable: 
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    
    def query(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    
    def query_id(self,l,r):
        if r>self.size:r=self.size
        
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]
 
    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo
 
show_flg=False
show_flg=True
ans=0

a,b,h,m=LI()
P=math.pi*2
t1=(h/12+m/60/12)*P
x,y=a*math.cos(t1),a*math.sin(t1)


t2=(m/60)*P
u,v=b*math.cos(t2),b*math.sin(t2)

ans=((x-u)**2+(y-v)**2)**0.5

print(ans)

Solution (Python):
def main():
    from sys import stdin
    import math
    a,b,h,m = map(int,stdin.readline().rstrip().split())
    h_rad = (h*60+m)/(12*60)*math.pi*2
    m_rad = m/60*math.pi*2

    x = (a*math.cos(h_rad), a*math.sin(h_rad))
    y = (b*math.cos(m_rad), b*math.sin(m_rad))

    dis = ((x[0]-y[0])**2 + (x[1]-y[1])**2)**0.5
    print(dis)

main()

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
import math
a,b,h,m = iim()

th_m = 6*m
th_h = 30*h+0.5*m

theta = abs(th_m-th_h) if abs(th_m-th_h)<180 else 360-abs(th_m-th_h)


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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


def input_int(): return int(input())

def map_int_input(): return map(int, input())

MII = map_int_input

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

def MII_to_index(): return map(to_index, input())

def MII_split_to_index(): return map(to_index, input().split())


def list_int_inputs(): return list(map(int, input()))

LII = list_int_inputs

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


def LII_2D(rows_number): return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number): return [LII_split() for _ in range(rows_number)]

import math

A, B, H, M = MII_split()

h_dig = (H + M / 60) * math.pi / 6
dig = M * math.pi / 30 - h_dig
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(dig))
print(ans)

Solution (Python):
a,b,c,d=map(int,input().split())
from math import*
hour=c*30+d*0.5
minu=d*6
print((a**2+b**2-2*a*b*cos(radians(hour-minu)))**0.5)

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

Solution (Python):

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

t = h + m/60

a_theta = t * 30
b_theta = (t * 360) % 360

theta = abs(a_theta - b_theta)

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

print(c)

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