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 bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys


buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B, H, M):
    s = [0, A]
    l = [0, B]
    sr = -2*math.pi * (H*60+M) / (12*60)
    lr = -2*math.pi * (M) / (60)

    s = [-math.sin(sr)*s[1],
         math.cos(sr)*s[1]]
    l = [-math.sin(lr)*l[1],
         math.cos(lr)*l[1]]
    return math.sqrt((s[0]-l[0])**2 + (s[1]-l[1])**2)


def main():
    A, B, H, M = read_int_n()
    print(slv(A, B, H, M))


if __name__ == '__main__':
    main()

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

from math import sqrt,cos,sin,pi



def dist(p,q):
  x1,y1 = p
  x2,y2 = q
  return sqrt((x1-x2)**2+(y1-y2)**2)
  
a_theta = (h*60+m)/720*2*pi
a_edge = [a*cos(a_theta),a*sin(a_theta)]

b_theta = (m)/60*2*pi
b_edge = [b*cos(b_theta),b*sin(b_theta)]

print(dist(a_edge,b_edge))

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

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * complex(cos(t1), sin(t1))
z2 = B * complex(cos(t2), sin(t2))

print(abs(z1 - z2))

Solution (Python):
import sys
import os
import math

def file_input():
    f = open('ABC168/input.txt', 'r')
    sys.stdin = f

def main():
    if os.getenv("ENV")=='LOCAL':
        file_input()

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

    A_r=360*(H*60+M)/(12*60)
    B_r=M*360/60

    ans=0
    dif=abs(A_r-B_r)
    if dif>180:
        dif=360-dif
        ans=math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(dif)))
    else:
        ans=math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(dif)))

    

    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

sp_s = math.radians(360 / (12 * 60) * (H*60 + M))
sp_l = math.radians(int(6 * M))

sx = A * math.sin(sp_s)
sy = A * math.cos(sp_s)

lx = B * math.sin(sp_l)
ly = B * math.cos(sp_l)

val1 = (lx - sx) ** 2
val2 = (ly - sy) ** 2

print(((lx - sx) ** 2 + (ly - sy) ** 2) ** .5)

Solution (Python):
import math

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

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

if hangle > 180 and mangle > 180:
    angle = abs(hangle-mangle)
elif hangle > 180:
    hangle = 360 - hangle
    angle = abs(hangle+mangle)
elif mangle > 180:
    mangle = 360 - mangle
    angle = abs(hangle+mangle)
else:
    angle = abs(hangle-mangle)

rad = math.radians(angle)

ans = float(math.sqrt(a*a + b*b - float(2*a*b*math.cos(rad))))
print('{:.10f}'.format(ans))

Solution (Python):
def main():
    import math
    import numpy as np
    A, B, H, M = [int(x) for x in input().split()]

    omegaA = 2*math.pi / (60*12)
    omegaB = 2*math.pi / 60
    t = H*60 + M
    thetaA = omegaA*t
    thetaB = omegaB*t

    zA = A * np.exp(1j * thetaA)
    zB = B * np.exp(1j * thetaB)

    print(abs(zA-zB))
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Solution (Python):
import math
from scipy.spatial import distance

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

jishin = math.radians(90 - (h + m / 60) * 30)
hunshin = math.radians(90 - m * 6)

x = (a * math.cos(jishin), a * math.sin(jishin))
y = (b * math.cos(hunshin), b * math.sin(hunshin))

ans = distance.euclidean(x, y)
print(ans)

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

pi = atan(1) * 4

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

yukati = H + M / 60.0

theta_zi = 2 * pi * yukati / 12
theta_fun = 2 * pi * yukati

zix = A * sin(theta_zi)
ziy = A * cos(theta_zi)
funx = B * sin(theta_fun)
funy = B * cos(theta_fun)

print("%.15f" % (((zix - funx) * (zix - funx) + (ziy - funy) * (ziy - funy)) ** 0.5))

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


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


y1, x1 = f(A, 0, math.radians(H * 30.0 + M * 0.5))
y2, x2 = f(B, 0, math.radians(M * 6.0))






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


print(d)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
A_rad = H/12*360 + ((M/60)*(360/12))
B_rad = M/60*360
rad = abs(A_rad - B_rad)
if rad >= 180:
    rad = 360 - rad

cosAB = round(math.cos(math.radians(rad)), 13)
C = ((A**2 + B**2) - 2*A*B*cosAB)**0.5
print(C)

Solution (Python):


import math

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

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):
import math
a, b, h, m = map(int,input().split())

a_s = (30 * h) % 360 + 0.5 * m
b_s = (6*m)

s = max(a_s,b_s) - min(a_s,b_s)
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(s)))
print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  

A, B, H, M = read_ints()

import numpy as np
thetaA = (H + M / 60) / 12 * 2 * np.pi
thetaB = (M / 60) * 2 * np.pi


theta = thetaA - thetaB if thetaA > thetaB else thetaB - thetaA
if theta > np.pi:
    theta = 2 * np.pi - theta

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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
H=((h%12)*30)+0.5*m
M=(m*6)
x=abs(H-M)
y=360-x
l=[x,y]
l.sort()
sita=l[0]
sita=math.radians(sita)
c=a**2+b**2-2*(a*b*math.cos(sita))
c=math.sqrt(c)
print(c)

Solution (Python):
import math

long, short, hour, minute = map(int, input().split())

total_minutes = 60 * hour + minute
long_angle = 0.5 * total_minutes
short_angle = (6.0 * total_minutes) % 360





if long_angle == short_angle:
    if long >= short:
        print(str(long - short))
        exit()
    else:
        print(str(short - long))
        exit()
elif long_angle - short_angle == 180 or long_angle - short_angle == -180 :
    print(str(long + short))
    exit()

if short_angle == 0:
    short_angle = 360

x = math.sqrt((long_angle - short_angle) ** 2) /2
y = 90 - x

a_down = short * math.sin(math.radians(x)) * 2
b_down = long * math.sin(math.radians(x)) * 2

c = b_down - (b_down - a_down) / 2

d = math.sqrt(long **2 - (b_down/2) **2 ) - math.sqrt(short ** 2 - (a_down/2) **2)

ans = math.sqrt(d**2 + c **2)

print(ans)

Solution (Python):
import math

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

if h * 360 / 12 + m * 360 / 60 / 12 > m * 360 / 60:
    r = (h * 360 / 12 + m * 360 / 60 / 12) - m * 360 / 60
else:
    r = m * 360 / 60 - (h * 360 / 12 + m * 360 / 60 / 12)

if r > 180:
    r = 360 - r





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

Solution (Python):
import math
A, B, H, M = map(int, input().split())
Hno = 30 * H + 0.5 * M
Mno = 6 * M
 
angle = Hno - Mno
if angle < 0:
    angle *= -1
 
cos = math.cos(math.radians(angle))
x = A ** 2 + B ** 2 - (2 * A * B * cos)
print(math.sqrt(x))

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

h_real = h+m/60
diff = (math.fabs(h_real-m/5))*30
cos = math.cos(math.radians(diff))

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

print(dis)

Solution (Python):
import math

a, b, h, m = map(float, input().split())
ap = bp = ax = ay = bx = by = d = 0
ap = h * 30 + m * 0.5
bp = m * 6

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

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

d = abs(ax - bx) ** 2 + abs(ay - by) ** 2

print(math.sqrt(d))

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
 
angle = (30 * H + 0.5 * M) - (6 * M)
if angle < 0:
    angle *= -1
 
cos = math.cos(math.radians(angle))
 
x = A ** 2 + B ** 2 - (2 * A * B * cos)
 
print(math.sqrt(x))

Solution (Python):
import math


def main():
    
    
    A,B,H,M = list(map(int, input().split(' ')))
    
    
    A_zure = H / 12 * 360
    B_zure = M / 60 * 360
    
    A_zure += (30 / 60) * M
    
    theta = abs(B_zure - A_zure)
    theta = min(360-theta, theta)
    
    
    C = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
    
    print(C** 0.5)
    
    

main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log, sin, cos, fabs, pi
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

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

longt = 6
mint = 1 / 2

time = h * 60 + m

longtt = longt * time % 360
mintt = mint * time % 360

w = fabs(longtt - mintt)

if w > 180:
    w = 360 - w

w = w / 180 * pi
l = sqrt(a**2 + b**2 - 2 * a * b * cos(w))
print(l)

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
import math

a,b,h,m=map(int,input().split())
nowh=30*h+(30/60)*m
nowm=6*m

if nowh==nowm:
    print(max(a,b)-min(a,b))
elif nowh==0:
    nowm=min(nowm,360-nowm)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowm)))**0.5)
elif nowm==0:
    nowh=min(nowh,360-nowh)
    print((a**2+b**2-2*a*b*math.cos(math.radians(nowh)))**0.5)
else:
    now=max(nowh,nowm)-min(nowh,nowm)
    print((a**2+b**2-2*a*b*math.cos(math.radians(now)))**0.5)

Solution (Python):
import math

a,b,h,m = list(map(int,input().split()))
r = abs((30*h + m *0.5) -  (6*m))
if r > 180:
	r = 360 - r
cos = math.cos(math.radians(r))
nijo = (a**2) + (b**2) - 2 * (a*b*cos)
ans = math.sqrt(nijo)
print(ans)

Solution (Python):
import math

s = input().split()

short_s = int(s[0])
long_s = int(s[1])
hours = int(s[2])
minutes = int(s[3])

d_short = 360 * hours/12 + 360 * (minutes/60) *(1/12)
d_long = 360 * minutes / 60

degree = d_short - d_long


length_2 = short_s * short_s + long_s * long_s  - 2 * short_s * long_s * math.cos(math.radians(degree))
print(math.sqrt(length_2))

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

hour_rad = ((2 * math.pi) / 720) * ((60 * h) + m)
min_rad =  ((2 * math.pi) / 60) * m
rad_ = abs(hour_rad - min_rad)
hour_cos = b * math.cos(rad_)
hour_sin = b * math.sin(rad_)

length_1 = a - hour_cos
length_2 = hour_sin

if rad_ == math.pi:
    ans = abs(length_1) + abs(length_2)
else:
    ans = math.sqrt((length_1 ** 2) + (length_2 ** 2))
print(ans)

Solution (Python):
import math
import numpy as np

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

x = ((h * 60 + m) * 360 /(720))
y = (m * 6)
num = abs(x - y)

print(math.sqrt(a * a + b * b - 2 * a * b * np.cos(np.radians(min(num, 360 - num)))))

Solution (Python):
import numpy as np

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

alpha = 360 * (h / 12) + 30 * (m / 60)
beta = 360 * (m / 60)
sa = abs(alpha - beta)

ans = np.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(2 * np.pi * (sa / 360)))
print(ans)

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

H = H - 12 if H>12 else H
zahyou_H = [A*math.sin(math.radians(360*H/12+30*M/60)), A*math.cos(math.radians(360*H/12+30*M/60))]
zahyou_M = [B*math.sin(math.radians(360*M/60)), B*math.cos(math.radians(360*M/60))]

kyori = math.sqrt((zahyou_H[0] - zahyou_M[0])**2 + (zahyou_H[1] - zahyou_M[1])**2)
print(kyori)

Solution (Python):
import math





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

a = H*30+M*0.5
b = M*6
X = abs(a - b)
kaku = min(X, 360 - X)


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

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

Solution (Python):
import sys
import math

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

zi = 0.5 * 60 * h + 0.5 * m
hun = 6 * h * 60 + 6 * m

if hun >= 360:
    for i in range(11):

        if hun >= 360:
            hun = hun - 360 
        elif hun < 360:
            break



if hun > zi:
    if hun - zi > 180:
        degree = 360 - hun + zi
    elif hun - zi < 180:
        degree = hun - zi
    elif hun - zi == 180:
        print(a + b)
        sys.exit(0)

elif zi > hun: 
    if zi - hun > 180:
        degree = 360 - zi + hun
    elif zi - hun < 180:
        degree = zi - hun
    elif zi - hun == 180:
        print(a + b)
        sys.exit(0)
elif hun == zi:
    if b >= a:
        print(b - a)
        sys.exit(0)
    else:
        print(a-b)
        sys.exit(0)

cosain = math.cos(math.radians(degree))

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

Solution (Python):
import math
s = input()
S = s.split()

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

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

if abs(Hang-Mang) > 180:
    Difang = 360 - abs(Hang - Mang) 
else:
    Difang = abs(Hang - Mang)

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

Solution (Python):
import math

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

m_kaku=math.radians(6*m)
h_kaku=math.radians(30*h+m*0.5)

kaku=m_kaku-h_kaku





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

print(c)

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

X=H*30+30*(M/60)
Y=M*6

ans=A*A+B*B-2*A*B*math.cos(math.radians(X-Y))
print(ans**0.5)

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


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

Solution (Python):
import math

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

if h * 360 / 12 +  m * 360 / 60 / 12 > m * 360 / 60:
    r = (h * 360 / 12 + m * 360 / 60 / 12 )- m * 360 / 60
else:
    r = m * 360 / 60 - (h * 360 / 12 + m * 360 / 60 / 12)

if r > 180:
    r = 360 - r

if r == 90:
    t = a ** 2 + b ** 2
    print(math.sqrt(t))
else:
    c = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(r))
    print(math.sqrt(c))

Solution (Python):
import math

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


P = 30*H + 0.5*M


Q = 6*M


S = abs(P-Q)


xb, yb = B * math.cos(math.radians(S)), B * math.sin(math.radians(S))


if 0 <= S < 90:
    l = math.sqrt((A - xb)**2 + (yb)**2)
    
elif 90 <= S < 180:
    l = math.sqrt((A - xb)**2 + (yb)**2)
    
elif 180 <= S < 270:
    l = math.sqrt((A - xb)**2 + (yb)**2)
    
elif 270 <= S < 360:
    l = math.sqrt((A - xb)**2 + (yb)**2)
print(l)

Solution (Python):
import math
A, B, H, M = [float(i) for i in input().split()]
C = float(abs(30.0*H + 0.50*M - 6.0*M))
if C > 180:
    C = 360.0 - C
c2 = A*A + B*B - 2*A*B*(math.cos((C/180.0)*math.pi))
c2 = math.sqrt(c2)
print(f'{c2:.{15}f}')

Solution (Python):
import numpy as np

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

w_h = 360/12*H + 30/60*M 
w_m = 360/60*M 

dif_angle = abs(w_h-w_m)
if dif_angle >= 180:
    dif_angle = 360 - dif_angle

rad = dif_angle/180*np.pi

C_2 = (A**2) + (B**2) - 2*A*B*np.cos(rad)
ans = np.sqrt(C_2)

print(ans)

Solution (Python):
import math

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

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

t = abs(h1-m1)
t = min(t, 360-t)

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

Solution (Python):



import sys
import math

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


def calc_coord(theta, length):
    
    if 0 <= theta <= 90:
        rad1 = math.radians(90-theta)
        min_x = length * math.cos(rad1)
        min_y = length * math.sin(rad1)
    elif 90 < theta <= 180:
        rad1 = math.radians(90 - theta)
        min_x = length * math.cos(rad1)
        min_y = length * math.sin(rad1)
    elif 180 < theta <= 270:
        rad2 = math.radians(450-theta)
        min_x = length * math.cos(rad2)
        min_y = length * math.sin(rad2)
    elif 270 < theta <= 360:
        rad2 = math.radians(450 - theta)
        min_x = length * math.cos(rad2)
        min_y = length * math.sin(rad2)

    return min_x, min_y


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

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

    min_x, min_y = calc_coord(min_theta, b)
    hour_x, hour_y = calc_coord(hour_theta, a)

    ans = math.sqrt((min_x - hour_x) ** 2 + (min_y - hour_y) ** 2)

    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
import math
A, B ,H, M=map(int,input().split())
shita = (60*H+M)/2
phi = 6*M
C2 =A**2 + B**2 - 2 * A * B *math.cos(math.radians(shita-phi))
ans=math.sqrt(abs(C2))
print(ans)

Solution (Python):
import math

inp = input().split()
tansin = int(inp[0])
tyosin = int(inp[1])
hour = int(inp[2])
minuts = int(inp[3])

minPer = minuts / 60 
hoPer = (hour / 12) + (minPer / 12)

adv = 0
late = 0
if minPer > hoPer:
  adv = minPer
  late = hoPer
else:
  adv = hoPer
  late = minPer

distancelaicio = adv - late
if distancelaicio > 0.5 :
  distancelaicio = (1-distancelaicio)  

kakudo = 360 * distancelaicio

a = (tansin**2) + (tyosin**2) - (2*tansin*tyosin*math.cos(math.radians(kakudo)))
print(a**0.5)

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

INF = 10 ** 10



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


total_minute = H * 60 + M

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

kakudo = abs(tyosin - tanshin)

if kakudo > 180:
    kakudo = 360 - kakudo

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

print(math.sqrt(C2))

Solution (Python):
import numpy as np
A = np.array(list(map(float, input().split())))
x1, y1 = A[0]*np.sin((A[2]+(A[3]/60))/6*np.pi), A[0]*np.cos((A[2]+(A[3]/60))/6*np.pi)
x2, y2 = A[1]*np.sin(A[3]/30*np.pi), A[1]*np.cos(A[3]/30*np.pi)
print(((x1-x2)**2+(y1-y2)**2)**0.5)

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

hour_rad = ((2 * math.pi) / 720) * ((60 * h) + m)
min_rad =  ((2 * math.pi) / 60) * m
rad_ = abs(hour_rad - min_rad)
hour_sin = b * math.cos(rad_)
hour_cos = b * math.sin(rad_)

length_1 = a - hour_sin
length_2 = hour_cos

if rad_ == math.pi:
    ans = abs(length_1) + abs(length_2)
else:
    ans = math.sqrt((length_1 ** 2) + (length_2 ** 2))
print(ans)

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

m = m * 6
h = h * 5 * 6 + (30 * m / 360)

if h == m:
    print(abs(b - a))
    exit()

if abs(h - m) == 180:

    print(a + b)
    exit()

a1, a2 = 0, 0
x1, y1, x2, y2 = 0,0,0,0



if h == 0:
    x1 = 0
    y1 = a
elif 0 < h < 90:
    a1 = tan(radians(90 - h))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
elif h == 90:
    x1 = a
    y1 = 0
elif 90 < h < 180:
    a1 = -tan(radians(h - 90))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
if h == 180:
    x1 = 0
    y1 = -a
if 180 < h < 270:
    a1 = tan(radians(270 - h))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1
if h == 270:
    x1 = -a
    y1 = 0
if 270 < h < 360:
    a1 = -tan(radians(h - 270))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1



if m == 0:
    x2 = 0
    y2 = b
elif 0 < m < 90:
    a2 = tan(radians(90 - m))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
elif m == 90:
    x2 = b
    y2 = 0
elif 90 < m < 180:
    a2 = -tan(radians(m - 90))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
if m == 180:
    x2 = 0
    y2 = -b
if 180 < m < 270:
    
    a2 = tan(radians(270 - m))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2
if m == 270:
    x2 = -b
    y2 = 0
if 270 < m < 360:
    a2 = -tan(radians(m - 270))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2





print(((x1-x2)**2 + (y1-y2)**2)**0.5)

Solution (Python):
import math

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

ang=abs(h*0.5-m*6)
if ang > 180:
  ang = 360-ang
if ang==180:
  print(a+b)
elif(ang==0):
  print(abs(b-a))
else:
  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 = list(map(int, input().split()))
omega_a = 30 * H
omega_b = 5.5 * M




thita = abs(omega_a-omega_b)


c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(thita)))
print('{:.22g}'.format(c))

Solution (Python):
import math

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

c = 0
timeA = H + (M/60)
argA = (1/12)*timeA

argB = (1/60)*M


sitaA = 360*argA
sitaB = 360*argB



if abs(sitaA-sitaB) == 180:
  print(A+B)
  exit()



if sitaA == sitaB:
  print(abs(B-A))
  exit()
elif sitaA > sitaB:
  c = math.sqrt(A**2 + B**2 - (2*A*B*math.cos(math.radians(sitaA-sitaB))))
elif sitaA < sitaB:
  c = math.sqrt(A**2 + B**2 - (2*A*B*math.cos(math.radians(sitaB-sitaA))))

print(c)

Solution (Python):
import math

if __name__ == "__main__":
    
    
    
    
    A, B, H, M = map(int, input().split())

    angle_h = 2*math.pi * (60*H + M) / (12 * 60)
    angle_m = 2*math.pi * M / 60
    diff = abs(angle_h - angle_m)
    gamma = diff if diff < math.pi else 2*math.pi - diff
    ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(gamma))
    print(ans)

Solution (Python):
import math


A,B,H,M=(input().split())
kakuH=(float(int(H)*30)+float(int(M)*0.5))
kakuM=int(int(M)*6)



if kakuH > int(kakuM + 180):
    kaku=float(kakuM+360-kakuH)
else :
    kaku=float(abs(kakuM-kakuH))

kaku=kaku*(float(math.pi)/180)

A=float(A)
B=float(B)
C=float(2*A*B*math.cos(kaku))

Ans1=float(int(A*A)+int(B*B)-float(C))
        
print(float(math.sqrt(Ans1)))

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





import numpy as np

angle = 2*np.pi*H/12 - 2*np.pi*M*11/(12*60)
length_squared = A**2 + B**2 - 2*A*B*np.cos(angle)
length = np.sqrt(length_squared)



print(length)

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




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

a2 = a**2
b2 = b**2

ans = math.sqrt((a2+b2)-(2*a*b*math.cos(math.radians(x))))
print(format(ans,'.15f') )

Solution (Python):
import math

def main():
    A, B, H, M = map(int, input().split())
    w_m = math.pi / 30
    w_h = math.pi / 360

    minutes = H * 60 + M
    
    rad_m = w_m * M
    rad_h = w_h * minutes

    rad = abs(rad_m - rad_h)

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

    out = float(c)

    print(out)
main()

Solution (Python):
import math
if __name__ == "__main__":
    A, B, H, M = map(int, input().split())
    angle = 0
    small = (H * 60 + M) * 0.5
    big = M * 6
    if small > big:
        angle = small - big
    else:
        angle = big - small
    cos_c = math.cos(math.radians(angle))
    print(math.sqrt(A**2 + B**2 -(2*A*B*cos_c)))

Solution (Python):
import numpy as np
import math
a,b,h,m = map(int, input().split())
ty = ((h*60+m)/60)/12
ta = (m)/60
if abs(ty-ta)>0.5:
    k = 1-abs(ty-ta)
else:
    k = abs(ty-ta)

if h*60+m==12*m:
    print(abs(b-a))
else:
    ans = a**2+b**2-2*a*b*(np.cos(k*2*math.pi))
    print(math.sqrt(ans))

Solution (Python):
import math
a,b,h,m=input().split(' ')
w1=2*math.pi/720.0
w2=2*math.pi/60.0
t1 = w1*(int(h)*60+int(m))
t2 = w2*int(m)
t3 = abs(t1-t2)
l3 = math.sqrt(int(a)*int(a)+int(b)*int(b)-(2*int(a)*int(b)*math.cos(t3)))
print(l3)

Solution (Python):
import math

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

H = 1/3 
M = 6 
g = 40 * (1/3)

M = m*6
h_ = 30*h
if(a >6):
  kakudo = abs((h_+m*(1/2))  - M)
  if(kakudo >= 360 - kakudo):
    kakudo = 360 - kakudo
  print(math.sqrt((a*a) + (b*b) - (2*a*b*(math.cos((math.radians(kakudo)))))))
if(a<6):
  kakudo = abs((h_+m*(1/2)) - M)
  if(kakudo >= 360 - kakudo):
    kakudo = 360 - kakudo
  print(math.sqrt((a*a) + (b*b) - (2*a*b*(math.cos((math.radians(kakudo)))))))

Solution (Python):
import math as mt 
  
def cal_cos(n): 
  
    accuracy = 0.00000000001
    x1, denominator, cosx, cosval = 0, 0, 0, 0
  
    
    n = n * (3.14159265358979323846264338328/ 180.0) 
  
    x1 = 1
  
    
    cosx = x1 
  
    
    cosval = mt.cos(n) 
    i = 1
    while (accuracy <= abs(cosval - cosx)): 
  
        denominator = 2 * i * (2 * i - 1) 
        x1 = -x1 * n * n / denominator 
        cosx = cosx + x1 
        i = i + 1
  
    return cosx 
  

def third_side(A, B, F): 
    angle = cal_cos(F) 
    return mt.sqrt((A * A) + 
                   (B * B) - 2 * A * B * angle) 
  


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

I=(M/60)
F=H+I
E=(F*30)
J=(M*6)

if E > J:
      G=E-J
else:
      G=J-E

angle=G

while angle > 360:
      
      angle=angle-360

if angle > 180:
      angle=360-angle

F=angle

print(third_side(A, B, F))

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

Solution (Python):
import math
from decimal import Decimal

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


d = 30*(h+m/60)-6*m
e = 360-d
f = min(d,e)
y = math.cos(math.radians(f))


x = float(a**2+b**2-2*a*b*y)
p = Decimal(x)
z = p**Decimal(0.5)

print("{0:.20f}".format(z))

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

do = 360*((h+m/60)/12 - m/60)
do = min(do, 360-do)
print((a**2 + b**2 - 2*a*b*math.cos(math.radians(do)))**(0.5))

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

print(math.sqrt(A*A + B*B - 2* A * B * math.cos(math.radians((60*H + M) * 5.5))))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
ha=h * 30 + (30 * (m / 60))
ma=360 * (m / 60)
angle=max(ha,ma)-min(ha,ma)
if angle>=180:
  angle = 360-angle
if angle==90:
  print(math.sqrt(a*a+b*b))
elif angle==0 or angle==180:
  if angle==0:
    print(abs(a-b))
  else:
    print(a+b)
else:
  angle=angle/180*math.pi
  
  ans=math.sqrt(a*a+b*b-2*a*b*math.cos(angle))
  print(ans)

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

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

print(ans)

Solution (Python):



import sys
import math

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


def calc_coord(theta, length):
    
    if 0 <= theta <= 90:
        rad1 = round(math.radians(90-theta), 11)
        min_x = length * round(math.cos(rad1), 11)
        min_y = length * round(math.sin(rad1), 11)
    elif 90 < theta <= 180:
        rad1 = round( math.radians(90 - theta), 11)
        min_x = round(length * math.cos(rad1),11)
        min_y = round(length * math.sin(rad1),11)
    elif 180 < theta <= 270:
        rad2 = round(math.radians(450-theta),11)
        min_x = round(length * math.cos(rad2),11)
        min_y = round(length * math.sin(rad2),11)
    elif 270 < theta <= 360:
        rad2 = round(math.radians(450 - theta),11)
        min_x = round(length * math.cos(rad2),11)
        min_y = round(length * math.sin(rad2),11)

    return min_x, min_y


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

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

    min_x, min_y = calc_coord(min_theta, b)
    hour_x, hour_y = calc_coord(hour_theta, a)

    ans = math.sqrt((min_x - hour_x) ** 2 + (min_y - hour_y) ** 2)

    print(ans)

if __name__ == "__main__":
    resolve()

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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

H += M / 60

t1 = 2 * pi * H / 12
t2 = 2 * pi * H

z1 = A * complex(cos(t1), sin(t1))
z2 = B * complex(cos(t2), sin(t2))

print(abs(z1 - z2))

Solution (Python):
import math
import decimal

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

l = 6*m
s = 30*h + 0.5*m
r = abs(l-s)
cos = math.cos(math.radians(r))
ans = ((a**2+b**2)-2*a*b*cos)**0.5

print('{:.21f}\n'.format(ans))

Solution (Python):
import math

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

rad_h = 0
rad_m = 0
rad_clock = 0
parts_cos = 0
ans = 0


rad_h = h * 30 + m * 0.5
rad_m = m * 6
if rad_h < rad_m:
    rad_clock = rad_m - rad_h
elif rad_h > rad_m:
    rad_clock = rad_h - rad_m
else:
    rad_clock = 0


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

Solution (Python):
import math
a,b,H,M=map(float,input().split())

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

c=a**2+b**2-2*a*b*math.cos(math.radians(ji-hun))
print ("{:.20f}".format(ｃ**0.5))

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

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

hour_rad = (360.0*float(H)/12.0 + 30.0*float(M)/60.0 ) * pi/180.0
min_rad = ( 360.0*float(M)/60.0 ) * pi/180.0

hour_x = A * cos(hour_rad)
hour_y = A * sin(hour_rad)

min_x = B * cos(min_rad)
min_y = B * sin(min_rad)

ans = ((hour_x-min_x)**2 + (hour_y-min_y)**2)**0.5
print(ans)

Solution (Python):
import math

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

H_ang = (H*60 + M)*0.5
M_ang = M*6

ang = M_ang - H_ang

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

print(math.sqrt(ans))