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

hh = (h/12)*360 + (m/60)*30
mm = (m/60)*360

rad = abs(hh-mm)

if rad > 180:
    rad = 360-rad

cos = math.cos(math.radians(rad))


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

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

rad = abs(H*30 - M *5.5)

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

print(math.sqrt(ans))

Solution (Python):
import math

def main():
    A, B, H, M = map(int, input().split(' '))
    h_ratio = 2*math.pi*(H + M/60)/12
    m_ratio = 2*math.pi*(M/60)

    a_pos_x = A*math.cos(h_ratio)
    a_pos_y = A*math.sin(h_ratio)
    b_pos_x = B*math.cos(m_ratio)
    b_pos_y = B*math.sin(m_ratio)

    dist = math.sqrt((a_pos_x - b_pos_x)**2 + (a_pos_y - b_pos_y)**2)
    print(dist)


if __name__ == '__main__':
    main()

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

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

gap=abs(h*30-m*5.5)*2*pi/360
tar=pow(a*a+b*b-2*a*b*cos(gap),0.5)
print(str(tar))

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


a, b, h, m = list(map(int, input().split()))
ha = ((h * 60 + m) / (12 * 60))
ma = m / 60

d = sqrt(
    (a * sin(2 * pi * ha) - b * sin(2 * pi * ma)) ** 2
     +
    (a * cos(2 * pi * ha) - b * cos(2 * pi * ma)) ** 2
    )
print(d)

Solution (Python):

from math import cos, sqrt, radians
A, B, H, M = map(int, input().split())
ln = M * 6
sh = H * 30 + 0.5 * M
theta = abs(ln - sh)
theta = min(theta, 360 - theta)
ans = sqrt(A**2 + B**2 - 2 * A * B * cos(radians(theta)))
print(ans)

Solution (Python):
import math

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

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

Solution (Python):
import math
A, B, H, M = map(int, input().split())
time = 60 * H + M
angle = 5.5 * time - (5.5 * time // 360 * 360)
angle = min(angle, 360 - angle)
cos_a = math.cos(math.radians(angle))
c2 = A**2 + B**2 - 2*A*B*cos_a
print(math.sqrt(c2))

Solution (Python):
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math



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

dega = h*30 + m*0.5
degb = m*6

dif = dega - degb if dega >= degb else degb - dega
dif = min(dif, 360 - dif)


c2 = a**2 + b**2 - 2*a*b*math.cos(dif*math.pi/180)

print(math.sqrt(c2))

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

dega = - 30*h - 0.5*m + 90
degb = - 6*m + 90

x_a = a*math.cos(math.radians(dega))
y_a = a*math.sin(math.radians(dega))
x_b = b*math.cos(math.radians(degb))
y_b = b*math.sin(math.radians(degb))


print(((x_a-x_b)**2+(y_a-y_b)**2)**0.5)

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

setrecursionlimit(10 ** 9)
INF = 1 << 60


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


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

minutes = H * 60 + M
angle = abs((12*M-minutes)/720)
ans = (A**2 + B **2 - 2 * A * B * cos(angle * 2  *pi)) ** 0.5
print(ans)

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

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

Solution (Python):
A,B,H,M=map(int,input().split())
import math
t=60*H+M
if H>=12:
    H-=12
tA=2*math.pi*t/60/12
tB=2*math.pi*M/60
ans=(A*math.cos(tA)-B*math.cos(tB))**2+(A*math.sin(tA)-B*math.sin(tB))**2
print(ans**0.5)

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

Solution (Python):
import math
A,B,H,M = [int(hoge) for hoge in input().split()]
Hkaku = H/12 + M/720
Mkaku = M/60
kaku = 360*abs(Hkaku-Mkaku)
kaku = min(kaku,360-kaku)
if kaku == 180:
    print(A+B);exit()
C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(kaku)))
print(C)

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

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

angleM = 2*pi*M/60
angleH = 2*pi*(H+M/60)/12
angle = abs(angleM-angleH)



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

Solution (Python):

from math import pi, cos, sin

a, b, h, m = map(int, input().split())
ax = a * cos(2 * pi * (h / 12 + m / 720))
ay = a * sin(2 * pi * (h / 12 + m / 720))
bx = b * cos(2 * pi * m / 60)
by = b * sin(2 * pi * m / 60)
print(((bx - ax) ** 2 + (by - ay) ** 2) ** 0.5)

Solution (Python):

import sys
from math import radians,cos

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    a,b,h,m = na()
    now = h*60+m
    wlong = now/2
    wshort = now*6
    c = pow(a*a+b*b-2*a*b*cos(radians(abs(wlong-wshort))),0.5)
    print(c)
    return


if __name__ == '__main__':
    main()

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

deg_H = (H * 60 + M) / 2
deg_M = (6 * M) % 360

theta = abs(deg_H - deg_M)

import math

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

Solution (Python):
from math import *

A, B, H, M = map(float, input().split())
H += M/60
print("%.10f"%hypot(A*cos(H/12*2*pi)-B*cos(M/60*2*pi), A*sin(H/12*2*pi)-B*sin(M/60*2*pi)))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

import math

a,b,h,m = na()
p = h*30+m*0.5
q = m*6
d = p-q

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

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

m_angle = 360 * (m/60)
h_angle = 360 * (h/12) + 30 * (m/60)

angle_dif = abs(m_angle-h_angle)

ans = (a**2 + b**2 - 2*a*b*math.cos(math.radians(angle_dif)))**(1/2)

print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
hun_deg = 360*(M/60)
ji_deg = 360*(H/12)+30*(M/60)
deg = abs(hun_deg-ji_deg)
ans = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(deg)))
print(ans)

Solution (Python):
a,b,h,m= list(map(int, input().split()))
hh=30*(h+m/60)
mm=6*m
sa=min(abs(hh-mm),360-abs(hh-mm))
from math import cos,pi
print((a**2+b**2-2*a*b*cos(sa/180*pi))**0.5)

Solution (Python):
import math

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

a = math.pi * 2 * (H + M / 60) / 12
b = math.pi * 2 * M / 60

c = abs(a-b)
c = min(c,math.pi*2-c)

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

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

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

a = (H / 12 + M / 60 /12) * 2 * math.pi
b = (M / 60) * 2 * math.pi

ans = (A * math.cos(a) - B * math.cos(b)) ** 2 + (A * math.sin(a) - B * math.sin(b)) ** 2
ans = ans ** 0.5
print(ans)

Solution (Python):
from math import cos, radians
a, b, h, m = map(int, input().split())
ar = h * 30 + m * 0.5
br = m * 6

r = min(360 - (abs(ar - br)), abs(ar - br))
print((a**2+b**2-2*a*b*cos(radians(r)))**0.5)

Solution (Python):
import math


def main():
    A, B, H, M = list(map(int, input().split(' ')))
    rad_a = 2 * math.pi * (60 * H + M) / 720
    rad_b = 2 * math.pi * M / 60
    theta = abs(rad_a - rad_b)
    print(math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(theta)))


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, H, M = MAP()

deg = (60*H + M)*5.5%360
arg = min(360-deg, deg)

ans = (A**2 + B**2 - 2*A*B*cos(radians(arg)))**0.5

print(ans)

Solution (Python):

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

h_deg = (h*30) + (m*0.5)
m_deg = m*6

subst = abs(h_deg-m_deg)
c = math.sqrt(a**2 + b**2 -(2*a*b*math.cos(math.radians(subst))))
print(c)

Solution (Python):
mod = 10**9+7
import sys
import math
from collections import Counter, defaultdict, deque
from itertools import product, permutations, combinations, combinations_with_replacement
from itertools import accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from math import ceil,floor
from copy import deepcopy
from heapq import heappop,heappush,heapify
import heapq










 








sys.setrecursionlimit(10 ** 6)

int1 = lambda x: int(x) - 1


p2D = lambda x: print(*x, sep="\n")

def II(): return int(sys.stdin.readline())

def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())




def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI(): return list(map(lambda x:int(x), sys.stdin.readline().split()))
def HI(): return list(map(lambda x:int(x)*(-1), sys.stdin.readline().split()))

A,B,H,M = MI()

d = abs(30*H - (330 * M / 60))
d = min(d,360-d)

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

print(ans)

Solution (Python):
import math

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

fun = 6 * m
ji = 30 * h + 0.5 * m
diff = min(abs(ji-fun),360-abs(ji-fun))
theta = math.radians(diff)
cos = math.cos(theta)
ans = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cos)
print(ans)

Solution (Python):

import math
import sys


def solve(A: int, B: int, H: int, M: int):
    sa = H * 30.0 + M * 0.5
    la = M * 6.0
    a = abs(sa - la)
    if a > 180:
        a = 360 - a
    print((A * A + B * B - 2 * A * B * math.cos(math.radians(a))) ** 0.5)


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


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

rada=t*0.5
radb=m*6
rad=rada-radb

rad=math.radians(min(rad,360-rad))

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

print(ans)

Solution (Python):
import math

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

t = 6*m - (30 *h + 0.5 * m)
cos = math.cos(math.radians(t))

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

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

time = H*60+M
rH = math.pi/6/60*(time%7200)
rM = math.pi/30*(time%60)
rad = abs(rH - rM)

l2 = A**2+B**2-2*A*B*math.cos(rH-rM)
print(l2**0.5)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
anga=h*30+m*0.5
angb=m*6
ang=abs(anga-angb)*math.pi/180.0
print(math.sqrt(a*a+b*b-2.0*a*b*math.cos(ang)))

Solution (Python):
import sys
from math import sqrt, cos, pi
def input(): return sys.stdin.readline().strip()


def main():
    A, B, H, M = map(int, input().split())
    time = H * 60 + M
    s = 0.5 * time
    l = 6 * time
    angle = min(abs(s - l), 360 - abs(s - l))
    dist = sqrt(A**2 + B**2 - 2 *A * B * cos(angle * 2 * pi / 360))
    print(dist)



if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

Solution (Python):
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

import sys
sys.setrecursionlimit(4100000)
rl = sys.stdin.readline

import math

A,B,H,M = Ints()

def dist(p1,p2):
    x1,y1 = p1
    x2,y2 = p2
    
    return ((x1-x2)**2+(y1-y2)**2)**0.5

def rotate(p,deg):
    x,y = p
    theta = deg*math.pi/180
    cos = math.cos(theta)
    sin = math.sin(theta)
    
    return [x*cos-y*sin, x*sin+y*cos]

deg1 = 30*H+M/2
deg2 = 6*M
p1 = [0,A]
p2 = [0,B]

p1n = rotate(p1,deg1)
p2n = rotate(p2,deg2)

print(dist(p1n,p2n))

Solution (Python):
import sys
from math import *

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    a,b,h,m=MI()
    r1=2*pi*m/60
    r2=2*pi*(h*60+m)/720
    rad=abs(r1-r2)
    if rad>pi:rad=2*pi-rad
    ans=sqrt(a**2+b**2-2*a*b*cos(rad))
    print(ans)

main()

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

t = 60 * h + m
hr = t / 2
mr = m * 6

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

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

c_angle=np.abs((h+m/60)*30-m*6)
if c_angle>=180:
    c_angle=360-c_angle
c_angle=c_angle/360*2*np.pi
print(str(np.sqrt(a**2+b**2-2*a*b*np.cos(c_angle))))

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

hkaku = 2*math.pi*(h*60+m)/(12*60)
mkaku = 2*math.pi*(m)/60

tmp = a*a+b*b - 2*a*b*math.cos(hkaku-mkaku)
print(math.sqrt(tmp))

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi, radians
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 


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

pb = (60*h + m)*6 % 360
pa = (60*h + m)*0.5 % 360
p = abs(pa - pb)
print(sqrt(a*a + b*b - 2*a*b*cos(radians(p))))

Solution (Python):
from math import cos, sin, pi
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    t_a = 2 * pi * H / 12 + (pi / 6) * (M / 60)
    t_b = 2 * pi * M / 60

    d = (A * cos(t_a) - B * cos(t_b))**2 + (A * sin(t_a) - B * sin(t_b))**2
    ans = pow(d, 0.5)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):




def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    

    
    

    a,b,h,m = map(int, input().split())
    jikan = 30*h + m/2
    hun = 6*m
    if jikan <= hun:
        kakudo = min(hun-jikan, 360-(hun-jikan))
    else:
        kakudo = min(jikan-hun, 360-(jikan-hun))

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

if __name__ == '__main__':
    main()

Solution (Python):
from math import sin,cos,tan,radians
A,B,H,M =map(int,input().split())

the_min = radians( (M/60)*360)
the_hour = radians( (H/12)*360 + 30* (M/60) )

a = [A*sin(the_hour),A*cos(the_hour)]
b = [B*sin(the_min),B*cos(the_min)]

s = (a[0]-b[0])**2 + (a[1]-b[1])**2
print(s**0.5)

Solution (Python):
import sys
from math import pi, cos, sin, sqrt
input = sys.stdin.readline
A, B, H, M = map(int, input().split())
H += M / 60
a = (A * cos(pi / 2 - H / 6 * pi), A * sin(pi / 2 - H / 6 * pi))
b = (B * cos(pi / 2 - M / 30 * pi), B * sin(pi / 2 - M / 30 * pi))

print(sqrt(abs(a[0] - b[0]) ** 2 + abs(a[1] - b[1]) ** 2))

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

l = 0.5*(H*60+M)
s = 6*M

d = min(abs(l-s), 360-abs(l-s))


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

Solution (Python):
import math
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b,h,m=INTM()
    mrad=360*m/60
    hrad=360*h/12+30*m/60
    mhdif =abs(mrad-hrad)
    
    if mhdif==180:
        ans=a+b
    elif mhdif==0 or mhdif==360:
        ans=abs(a-b)
    elif mhdif>180:
        mhdif=360-mhdif
    
    if 0<mhdif<180:
        ans=(a**2+b**2-2*a*b*math.cos(math.radians(mhdif)))**0.5
    
    print(ans)
    
if __name__ == '__main__':
    do()

Solution (Python):
import math

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

al=h*360/12+(m/60)*30

ss=(m/60)*360

ff=min(abs(ss-al),360-abs(ss-al))

fg=math.radians(ff)

x=pow(a,2)+pow(b,2)-2*a*b*math.cos(fg)
ans=math.sqrt(x)
print(ans)

Solution (Python):


from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    a,b,h,m = mi()
    h = h*30+m/2
    m = m*6
    c = math.cos(math.radians(abs(h-m)))
    ans = (a**2+b**2-2*b*a*c)**0.5
    print(ans)









main()

Solution (Python):
from math import cos,sin,pi,sqrt
A,B,H,M = map(int,input().split())
m = 60*H + M
x = [A*cos(2*pi*m/(12*60)),B*cos(2*pi*m/60)]
y = [A*sin(2*pi*m/(12*60)),B*sin(2*pi*m/60)]

print(sqrt((x[0]-x[1])**2 + (y[0]-y[1])**2))

Solution (Python):
import math

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

long1 = 2*math.pi*m/60
short1 = 2*math.pi*(h/12+m/720)

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

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

Solution (Python):
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
a,b,h,m=NM()
from math import cos,sqrt,pi
s=h/12+m/720-m/60
print(sqrt(a**2+b**2-2*a*b*cos(2*pi*(s))))

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

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

hun=m/30
use=math.pi*(ji-hun)
ans=(a**2+b**2-2*a*b*math.cos(use))**0.5
print(ans)

Solution (Python):
import sys
import math
import fractions
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10**7)

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

short_rad = math.radians((H * 60 + M) * 0.5)
long_rad = math.radians(M * 6)

diff = abs(short_rad - long_rad)

l = A * A + B * B - 2 * A * B * math.cos(diff)

print(math.sqrt(l))

Solution (Python):
import math
a, b, h, m = [int(i) for i in input().split()]
angle = abs(0.5 * math.pi/180 * (60*h - 11*m))
print(math.sqrt(a**2+b**2 - 2 * a * b * math.cos(angle)))

Solution (Python):
import math

A, B, H, M = map(int, input().split())
da = math.radians(30 * H - 5.5 * M)
print(math.sqrt(A * A + B * B - 2 * A * B * math.cos(abs(da))))

Solution (Python):
import math
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    A, B, H, M = ZZ()
    Mt = math.radians(6 * M)
    Ht = math.radians(30 * H + M/2)
    Mx = B * math.cos(Mt)
    My = B * math.sin(Mt)
    Hx = A * math.cos(Ht)
    Hy = A * math.sin(Ht)
    print(((Hx - Mx) ** 2 + (Hy - My) ** 2) ** 0.5)

    return

if __name__ == '__main__':
    main()

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

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
import math
def readInts():
  return list(map(int,input().split()))
def main():
    a,b,h,m = readInts()
    h = h-12 if h >=12 else h

    h_ = 30 * h + 30 * m / 60
    m_ = 360 * m / 60

    kakudo = min(abs(m_-h_),360-abs(m_-h_))
    
    c = pow(a**2 + b**2 - 2*a*b*math.cos(math.radians(kakudo)),.5)
    print(c)
if __name__ == '__main__':
  main()

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

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

Solution (Python):
import math

A, B, H, M = map(int, input().split())
c = math.cos(math.pi * (M / 30 - H / 6 - M / 360))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * c))

Solution (Python):


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

import math
A_x = A * math.cos(2 * math.pi * (H + M / 60.) / 12.)
A_y = A * math.sin(2 * math.pi * (H + M / 60.) / 12.)
B_x = B * math.cos(2 * math.pi * M / 60.)
B_y = B * math.sin(2 * math.pi * M / 60.)

print('{:.15f}'.format(math.sqrt((A_x - B_x) ** 2 + (A_y - B_y) ** 2)))

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

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


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

    deg_a = H * 30 + M * (30 / 60)
    deg_b = M * (360 / 60)
    deg = min(abs(deg_a - deg_b), 360 - abs(deg_a - deg_b))
    deg = deg / 360 * 2 * math.pi

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


if __name__ == "__main__":
    main()

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


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


def main():
    A, B, H, M = inpl()
    deg = abs(30 * H - 5.5 * M)

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

    print('{:.10f}'.format(ans**0.5))

    return


if __name__ == '__main__':
    main()

Solution (Python):
def examA():
    S = {0:"pon",1:"pon",2:"hon",3:"bon",4:"hon",5:"hon",6:"pon",7:"hon",8:"pon",9:"hon"}
    N = SI()
    ans = S[int(N[-1])]
    print(ans)
    return

def examB():
    K = I()
    S = SI()
    N = len(S)
    if N<=K:
        ans = S
    else:
        ans = S[:K]+"..."
    print(ans)
    return

def examC():
    A, B, H, M = LI()
    a = abs(H*30 - M*5.5)
    deg = min(360-a,a)*math.pi/180
    
    ans = (A**2 + B**2 - 2*A*B*math.cos(deg))**(0.5)
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Solution (Python):
import sys
import math

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

a, b, h, m = na()
hh = math.pi*2*(h/12+m/60/12)
mm = math.pi*2*m/60

ax = math.cos(hh)*a
ay = math.sin(hh)*a
bx = math.cos(mm)*b
by = math.sin(mm)*b
print(f"{math.sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by)):.14f}")

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




a=(2*math.pi/12/60)*(H*60+M)


b=(2*math.pi/60)*(M)


theta=a-b


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

angle1 = math.pi * 2 / 12.0 * (H + M / 60.0)
angle2 = math.pi * 2 / 60.0 * M

x1 = math.cos(angle1) * A
y1 = math.sin(angle1) * A

x2 = math.cos(angle2) * B
y2 = math.sin(angle2) * B

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

Solution (Python):
from math import pi, sin, cos, sqrt
a,b,h,m=map(int,input().split())
c=2*pi/12*h + pi/6/60*m
d=2*pi/60*m
ax=a*cos(c)
ay=a*sin(c)
bx=b*cos(d)
by=b*sin(d)
print(sqrt((ax-bx)**2 + (ay-by)**2))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h=h/12*360 + m/60*30
m=m/60*360
c = h-m
c = min(360-c,c)*math.pi/180
x = (a**2+b**2-2*a*b*math.cos(c))**(0.5)
print("{:.20f}".format(x))

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


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


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7


def main():
    A, B, H, M = map(int, input().split())
    diff = 30 * H
    if M < diff / 5.5:
        D = diff - 5.5 * M
    else:
        D = 5.5 * M - diff
    print((A ** 2 + B ** 2 - 2 * A * B * cos(math.radians(D))) ** (1 / 2))


if __name__ == "__main__":
    main()

Solution (Python):
import bisect
import collections
import functools
import heapq
import math
from collections import deque
from collections import defaultdict
MOD = 10**9+7

a,b,h,m = map(int,(input().split()))
hkakudo = math.radians(30*h+0.5*m)
mkakudo = math.radians(6*m)
kakudo = abs(hkakudo-mkakudo)
ans = a**2 + b**2 - 2*a*b*math.cos(kakudo)
print(ans**0.5)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log,cos,pi 
from heapq import 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 copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X,Y,a,b=MI()
    a%=12
    A = 360 * (a + b/60)/12
    B = 360 * b/60
    theta = min(abs(A-B),360-abs(A-B)) 
    
    theta /= 180
    theta *= pi
    ans = X**2 + Y**2 - 2*X*Y*cos(theta)
    ans = sqrt(ans)
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from math import radians, sin, cos, sqrt
A,B,H,M = list(map(int, input().split()))

frad = radians(M*6)
fx,fy = B * sin(frad), B * cos(frad)

jrad = radians(H*30 + M * 0.5)
jx,jy = A * sin(jrad), A * cos(jrad)

dis = sqrt( (jx - fx) ** 2 + (jy - fy) ** 2)
print(dis)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,h,m = LI()
x = 30 * h +  (30 / 60) * m
y = 6 * m
z = abs(x-y)
z = min(360 - z, z)
c = a**2 + b**2 - 2*a*b*math.cos(math.radians(z))
print(math.sqrt(c))

Solution (Python):
import math

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

r_h = H * 30 + M * 0.5
r_m = M * 6

r = abs(r_h-r_m)
s = math.cos(math.radians(r))

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

print(C)

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

Solution (Python):
import math

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

hangle = 2*math.pi/360*(H*30+M/2)
mangle = 2*math.pi/360*M*6

hx = A*math.cos(hangle)
hy = A*math.sin(hangle)
mx = B*math.cos(mangle)
my = B*math.sin(mangle)

dx = hx-mx
dy = hy-my
d2 = dx*dx+dy*dy
d = d2**0.5
print(d)

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




x = H * 60 + M
cos_x = x / 2
cos_y = 6 * M
max_xy = min(abs(cos_x - cos_y) , 360 - abs(cos_x - cos_y))

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

print(ans)

Solution (Python):
import math

a,b,h,m = map(int,input().split())
ah = 30 * h + m * 0.5
am = 6 * m
ang = abs(ah - am)
ang = min(ang, 360 - ang)
ans = (a*a+b*b-2*a*b*math.cos(math.radians(ang))) ** 0.5


print(ans)