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):
from math import cos
from math import pi

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

H_R = (H * 60 + M) / 720 * (pi * 2)
M_R = M / 60 * (pi * 2)

ans = (A ** 2 + B ** 2 - 2 * A * B * cos(H_R - M_R)) ** 0.5

print(ans)

Solution (Python):
import math

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

rad_hour = math.pi * 2 * (h/12 + (m/60)/12)
rad_min = math.pi * 2 * (m/60)

rad = max(rad_hour, rad_min) - min(rad_hour, rad_min)

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

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

Solution (Python):
import math

a,b,h,m = map(float,input().rstrip().split())
rad_h = 2*math.pi/12*(h+m/60)
rad_m = 2*math.pi/60*m

delta_theta = abs(rad_m - rad_h)
if delta_theta > math.pi:
    delta_theta = 2*math.pi-delta_theta
c = math.sqrt(a*a + b*b - 2*a*b*math.cos(delta_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(math.radians(30 * H - 5.5 * M))))

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

A, B, H, M = map(int, input().split())
a = (30*H + 0.5*M)/180*pi
b = 6*M/180*pi
len_x = A*cos(a)-B*cos(b)
len_y = A*sin(a)-B*sin(b)
ans = sqrt(len_x**2+len_y**2)
print(ans)

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

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

theta = (h / 12 + m / (60 * 12) - (m / 60))
theta *= 2 * pi
print(sqrt((a ** 2) + (b ** 2) - (2 * a * b * cos(theta))))

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

Solution (Python):
import numpy as np
def main():
	A, B, H, M = map(float, input().split())
	R = H/12 + M*0.5/360
	r = M/60
	cos = np.cos((R-r)*2*np.pi)
	C = np.sqrt(A*A + B*B - 2*A*B*cos)
	print(C)
 
if __name__ == '__main__':
	main()

Solution (Python):
import math
 
A,B,H,M=map(int, input().split())
 
sh=math.pi*(H+M/60)/6
sm=math.pi*M/30
 
s=abs(sh-sm)
 
C=math.sqrt(A**2+B**2-2*A*B*math.cos(s))
 
print(C)

Solution (Python):
import math
def main():
	A, B, H, M = map(float, input().split())
	R = H/12 + M*0.5/360
	r = M/60
	cos = math.cos((R-r)*2*math.pi)
	C = math.sqrt(A*A + B*B - 2*A*B*cos)
	print(C)

if __name__ == '__main__':
	main()

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


def dst(a,b,deg):
    return ((a**2+b**2)-(2*a*b*math.cos(math.radians(deg))))**0.5

deg_1 = (60*h+m)*0.5
deg_2 = m*6
deg = abs(deg_1-deg_2)

if deg > 180:
    deg = 360-deg

ans = dst(a,b,deg)
print(ans)

Solution (Python):
import  numpy as np

np.set_printoptions(precision=10)

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

dh=H/12*360+30*M/60
dm=M/60*360
sita=np.abs(dh-dm)

x=np.sqrt(A**2+B**2-2*A*B*np.cos(np.deg2rad(sita)))
print(x)

Solution (Python):
from math import sin,cos,pi
a, b, h, m = [int(i) for i in input().split()]
t = (h + m / 60)*2*pi
 
ax, ay = a * cos(t / 12), a * sin(t / 12)
bx, by = b * cos(t), b * sin(t)
print(((ax-bx)**2+(ay-by)**2)**0.5)

Solution (Python):
import numpy as np
from math import *
temp = input()
[a, b, h, m] = [float(comp) for comp in temp.split()]
h_co = a * np.array([cos(2.0 * pi * (h+m/60.) / 12.),
                     sin(2.0 * pi * (h+m/60.) / 12.)])
m_co = b * np.array([cos(2.0 * pi * m / 60.), sin(2.0 * pi * m / 60.)])
ans = np.linalg.norm(h_co-m_co)
print(ans)

Solution (Python):
import math

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

c = (h*30)+(m*(1/2))
d = m*6

e = abs(c - d)

theta = min(360-e,e)

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

print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
HR = (M * 360)/60
MR = (H * 60 + M)*360/(12*60)
d = abs(MR - HR)
ans = ((A**2 + B**2) - (2*A*B*math.cos(math.radians(d))))**(1/2)
print(str(ans))

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

Solution (Python):
import math
A, B, H, M = [int(n) for n in input().split(' ')]

H_deg = (360/(12*60))*(H*60+M)
M_deg = (360/60)*M

deg = abs(H_deg-M_deg)
if deg > 180:
  deg = 360-deg

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

print(ans)

Solution (Python):
import math
def squared(x):
    return x**2

def theta(h, m):
    mr = 6 * m
    hr = 30 * h + m / 2
    r = abs(float(hr) - float(mr))
    return r

def length(a, b, h, m):
    return math.sqrt(squared(a) + squared(b) - 2 * a * b * math.cos(math.radians(theta(h, m))))


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

print(length(a, b, h, m))

Solution (Python):
import numpy as np
input_initial=input().split()
a=int(input_initial[0])
b=int(input_initial[1])
h=int(input_initial[2])
m=int(input_initial[3])

time=60*h+m
a_kakudo=0.5*time
b_kakudo=6*m

if a_kakudo>=b_kakudo:
    kakudo=a_kakudo-b_kakudo
    if kakudo>180:
        kakudo=360-kakudo

else:
    kakudo=b_kakudo-a_kakudo
    if kakudo>180:
        kakudo=360-kakudo

kakudo=2*np.pi*kakudo/360

c=np.sqrt(a**2+b**2-2*a*b*np.cos(kakudo))
float(c)
print(c)

Solution (Python):

from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement
from __builtin__ import xrange as range
from math import ceil, factorial, log,tan,pi,cos,sin,radians
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(m):
    n=1
    primes = {}
    arr=set([])
    for i in range(2, int(m ** 0.5) + 1):
        a = n // i
        b = m // i
        for k in range(max(2, a), b + 1):
            c = i * k
            primes[c] = 1

    for i in range(max(n, 2), m + 1):
        if i not in primes:
            arr.add(i)

    return arr


class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n
 
    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a
 
    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a != b:
            if self.size[a] < self.size[b]:
                a, b = b, a
 
            self.num_sets -= 1
            self.parent[b] = a
            self.size[a] += self.size[b]
 
    def set_size(self, a):
        return self.size[self.find(a)]
 
    def __len__(self):
        return self.num_sets

def isprime(t):
    for i in range(2,int(t**0.5)+1):
        if t%i==0:
            return False
    return True
def semiprime(x):
    for i in range(2,int(x**0.5)+1):
        if x%i==0:
            if isprime(i) and isprime(x//i) and i!=x//i:
                return True
    return False



def main():

    
    

    a,b,h,m=map(int,input().split())
    hangle=(360*h)/12 + (30*m)/60
    mangle=m*360/60
    angle=abs(hangle-mangle)
    vector_distance=a**2+b**2-2*a*b*cos(radians(angle))
    print(vector_distance**0.5)



        

        
    




    





BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
import math
A,B,H,M=map(int,input().split())
long=360*H/12+30*M/60
short=360*M/60
kakudo=abs(long-short)
answer=A**2+B**2-2*A*B*math.cos(math.radians(kakudo))
print(answer**0.5)

Solution (Python):
import sys
import math

a,b,h,m=map(int, sys.stdin.readline().rstrip().split())
m_angle = m*6
h_angle = h*30+m/2
theta=abs(h_angle-m_angle)
if theta>180:theta=360-theta
c = a**2+b**2-2*a*b*math.cos(math.radians(theta))
print(c**0.5)

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()))
from math import pi,sin,cos
a,b,h,m = iim()
h += m/60

th_h = 2*pi*h/12
th_m = 2*pi*h

ah = a*complex(cos(th_h),sin(th_h))
bm = b*complex(cos(th_m),sin(th_m))

print(abs(ah-bm))

Solution (Python):
import math

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

h = ((M * 0.5) + H * 30)
m = M * 6

if h == 0:
  h = 360
if m == 0:
  m = 360

c = h - m
if c < 0:
  c = c * -1


sin_d = math.cos(math.radians(c))


line = (A ** 2) + (B ** 2) - (2 * A * B * sin_d)
print(math.sqrt(line))

Solution (Python):
import math
 
A,B,H,M=map(int,input().split(" "))
 
hour=[A*math.cos(math.radians(H*30+M/2)),A*math.sin(math.radians(H*30+M/2))]
minute =[B*math.cos(math.radians(M*6)),B*math.sin(math.radians(M*6))]
if (hour[0]>=0 and minute[0]>=0) or (hour[0]<0 and minute[0]<0):
    a=minute[0]-hour[0]
else:
    a=abs(minute[0])+abs(hour[0])
    
if (hour[1]>=0 and minute[1]>=0) or (hour[1]<0 and minute[1]<0):
    b=minute[1]-hour[1]
else:
    b=abs(minute[1])+abs(hour[1])    
print('{:.16f}'.format(math.sqrt(pow(a,2)+pow(b,2))))

Solution (Python):
import math
from sys import stdin
A, B, H, M = [int(_) for _ in stdin.readline().rstrip().split()]
theta = ((H*60+M)/720 - M/60)*(math.pi*2)
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)
ans = math.sqrt(ans)
print(ans)

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

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

dm = - pi/30*M + pi/2

dh = - (pi/6*H +  M*(pi/6/60)) + pi/2

xA = A*cos(dh)
yA = A*sin(dh)
xB = B*cos(dm)
yB = B*sin(dm)

print(sqrt( (xA-xB)**2 + (yA-yB)**2 ))

Solution (Python):
import math

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

c(a,b,h,m)

Solution (Python):
import numpy as np
a, b, h, m = map(int, input().split())
argh = 2 * np.pi * ((h + (m / 60) ) / 12)
argm = 2 * np.pi * (m / 60)
arg = abs(argh - argm)
if arg > np.pi:
    arg = 2 * np.pi - arg
print((a**2 + b**2 - 2 * a * b * np.cos(arg)) ** (1/2))

Solution (Python):
import math as ma

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

al = 360 * (h + m /60) /12
bl = m*6
rad = ma.radians(min(abs(bl - al), 360 - abs(bl - al)))
r = ma.sqrt(a**2 + b**2 -2*a*b*ma.cos(rad))
print(r)

Solution (Python):
import math

A_senti, B_senti, H_ji, M_fun = map(int, input().split())

rad_A = 360 * (H_ji + M_fun / 60) / 12
rad_B = 360 * (M_fun) / 60

rad = math.radians(min(abs(rad_B - rad_A), 360 - abs(rad_B - rad_A)))

square_c = A_senti ** 2 + B_senti ** 2 - 2 * A_senti * B_senti * math.cos(rad)
ans = math.sqrt(square_c)

print(ans)

Solution (Python):
import math
     
A,B,H,M = map(int, input().split())
     
hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
      
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
else:
  degree = mindegrees - hourdegrees
      
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Solution (Python):
import math
     
A,B,H,M = map(int, input().split())
     
hourdegrees = ( H * 60 + M ) * (0.5)
mindegrees = M*(6)
      
if mindegrees < hourdegrees:
  degree = hourdegrees - mindegrees
elif mindegrees > hourdegrees:
  degree = mindegrees - hourdegrees
elif mindegrees == hourdegrees:
  degree = 0
      
distance = math.sqrt(A ** 2 + B ** 2 -2 * A * B * math.cos(math.radians(degree) ) )
print(distance)

Solution (Python):
import math

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


A = int(A)
B = int(B)
H = int(H)
M = int(M)

Mdeg = M / 60 * 360
Hdeg = M / 60 * (360 / 12) + H / 12 * 360
angle = math.radians(abs(Hdeg - Mdeg))

L = (A ** 2 + B ** 2 - 2 * A * B * math.cos(angle))
L = L ** 0.5

print(L)

Solution (Python):


from numpy import pi, cos

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

theta = (m / 60 - (h + m / 60) / 12) * 2 * pi

c2 = a**2 + b**2 - 2 * a * b * cos(theta)
print(c2 ** 0.5)

Solution (Python):
import math

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

theta_jisin = 30 * H + 0.5 * M
theta_hunsin = 6 * M

delta_x = A * math.cos(math.radians(theta_jisin)) - B * math.cos(math.radians(theta_hunsin))
delta_y = A * math.sin(math.radians(theta_jisin)) - B * math.sin(math.radians(theta_hunsin))
print(math.sqrt(delta_x*delta_x + delta_y*delta_y))

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

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

hour_rad = (60 * H + M) / 720 * (2 * math.pi)
minute_rad = (M / 60) * (2 * math.pi)
theta = hour_rad - minute_rad

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

Solution (Python):

import math

h_len,m_len,h,m = map(int,input().split())
m_deg = m/60*360
h_deg = h/12*360 + m/60*1/12*360
theta = math.radians(abs(m_deg-h_deg))

z = math.sqrt(h_len**2 + m_len**2 - 2*h_len*m_len*math.cos(theta))

print(z)

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

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf


a,b,h,m = imap()
h += m/60
r1 = 2*PI * (h/12)
r2 = 2*PI * (m/60)
z1 = cma.rect(a, r1)
z2 = cma.rect(b, r2)
ans = abs(z1 - z2)
print(ans)

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf


a,b,h,m = imap()
h += m/60
r1 = 2*PI * (h/12)
r2 = 2*PI * (m/60)
z1 = a * np.exp(r1 * 1j)
z2 = b * np.exp(r2 * 1j)
ans = abs(z1 - z2)
print(ans)

Solution (Python):
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

a,b,h,m = imap()
h += m/60
r1 = 2*PI * (h/12)
r2 = 2*PI * (m/60)
z1 = a * np.exp(-r1 * 1j)
z2 = b * np.exp(-r2 * 1j)
ans = abs(z1 - z2)
print(ans)

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

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

theta_H = H / 12 * 2 * pi + M / 12 / 60 * 2 * pi
theta_M = M / 60 * 2 * pi

D = sqrt((A*sin(theta_H)-B*sin(theta_M))**2+(A*cos(theta_H)-B*cos(theta_M))**2)

print(D)

Solution (Python):
import math

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

TWO_PI = 2 * math.pi

dm = M / 60 * TWO_PI
dh = (H + M / 60) / 12 * TWO_PI

ax = A * math.cos(dh)
ay = A * math.sin(dh)
bx = B * math.cos(dm)
by = B * math.sin(dm)

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

print(ans)

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

ans = 0
cos = 0
mi = m/60 * 360 
hour = (60*h + m)/720 * 360 

cos = math.cos(math.radians(hour - mi))
ans = a*a + b*b -2*a*b*cos

ans = ans ** (1/2)
print(ans)

Solution (Python):
import math











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

angh = (h*math.pi/6) + (m*math.pi/360)
angm = m*math.pi/30

d = a*a + b*b - 2*a*b*math.cos(angh - angm)
print(math.sqrt(d))

Solution (Python):
import math

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

x1=360*m/60
x2=30*h+30*m/60
theta=min(abs(x1-x2),360-abs(x1-x2))

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

Solution (Python):

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

import math

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

x_m = (m/60)*2*math.pi

x = x_h-x_m
if x < 0:
  x *= -1
if x > math.pi:
  x = 2*math.pi-x

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

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

l = 6 * M

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

abs = abs(l - s)
pi = math.radians(abs)
ans = (A*A + B*B) - (2 * A * B) * math.cos(pi)
print(math.sqrt(ans))

Solution (Python):
import math

A, B, H, M = map(float, input().split(' '))
alpha = M / 30 * math.pi
theta = (60 * H + M) / 360 * math.pi
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(abs(alpha - theta))))

Solution (Python):
import math
a,b,h,m = map(int,input().split())
zi = h * 30 + m * 0.5
hun = m * 6
kaku = abs(zi-hun)
if kaku > 180:
    kaku = 360 - kaku
kaku = math.cos(math.radians(kaku))
ans2 = a**2 + b**2 - 2*a*b*kaku
print(math.sqrt(ans2))

Solution (Python):
import math



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

rad = 2 * math.pi * ((H / 12 + M / (60 * 12)) - M / 60)
ans = math.sqrt(A ** 2 + B ** 2 - (2 * A * B * math.cos(rad)))

print(ans)

Solution (Python):
import math
 
def main():
    a, b, h, m = [int(x) for x in input().split()]
    theta_a = (60 * h + m) / 720 * (2 * math.pi)
    theta_b = (m / 60) * (2 * math.pi)
    xh = a * math.cos(theta_a)
    yh = a * math.sin(theta_a)
    xm = b * math.cos(theta_b)
    ym = b * math.sin(theta_b)
    ans = math.sqrt((xh - xm)**2 + (yh - ym)**2)
    return ans
 
if __name__ == '__main__':
    print(main())

Solution (Python):
from math import*
a, b, H, M = map(int, input().split())
p = abs((H*60+M)/2%360 - M*6)
print((a*a + b*b - 2*a*b*cos(radians(min(p, 360-p))))**.5)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
hour = 30*h+0.5*m
minutes = m*6

Long = max(hour,minutes)
short = min(hour,minutes)

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

Solution (Python):


import math

p = [int(s) for s in list(input().split())]
A = p[0]
B = p[1]
H = p[2]
M = p[3]

theta = math.fabs(H + M / 60 - M * 12 / 60) * 2 * math.pi / 12
theta2 = 2 * math.pi - theta

theta = min(theta,theta2)


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

Solution (Python):
import math


def main():
    a, b, h, m = [int(x) for x in input().split()]
    theta_a = (60 * h + m) / 2
    theta_b = 6 * m
    xa = a * math.cos(math.radians(theta_a))
    ya = a * math.sin(math.radians(theta_a))
    xb = b * math.cos(math.radians(theta_b))
    yb = b * math.sin(math.radians(theta_b))
    ans = math.sqrt((xa - xb)**2 + (ya - yb)**2)
    return ans


if __name__ == '__main__':
    print(main())

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

s = np.zeros([2])
l = np.zeros([2])

s_deg = np.pi/2 - 2*np.pi/(12*60)*(60*H+M)
l_deg = np.pi/2 - 2*np.pi/60*M

s[0]=A*np.cos(s_deg)
s[1]=A*np.sin(s_deg)
l[0]=B*np.cos(l_deg)
l[1]=B*np.sin(l_deg)

print(np.sqrt((s[0]-l[0])**2+(s[1]-l[1])**2))

Solution (Python):
from math import radians, sin, cos, sqrt
A,B,H,M = map(int, input().split())
radM = radians(M * 6)
radH = radians((M/2) + H*30)
print(((float(A*cos(radH)-B*cos(radM))**2+float(A*sin(radH)-B*sin(radM))**2))**0.5)

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

a1 = math.pi*(h+m/60)/6
a2=m*math.pi/30 

cos = math.cos(a1-a2)
print((a**2+b*b-2*a*b*cos)**.5)

Solution (Python):
import math

def solve():
    ms = h*60 + m
    angle1 = 2 * math.pi * (ms % (12 * 60)) / float (12 * 60)
    angle2 = 2 * math.pi * (ms % (60)) / float (60)
    pos1 = [math.sin(angle1) * a, math.cos(angle1) * a]
    pos2 = [math.sin(angle2) * b, math.cos(angle2) * b]
    dist = math.sqrt((pos1[0] - pos2[0])**2 + (pos1[1] - pos2[1])**2)
    print(dist)
    return

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

Solution (Python):
import math

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

v1 = 1/2
v2 = 6
t = 60 * float(H) + float(M)

u1 = (90 - (float(v1) * float(t)))
u2 = (90 - (float(v2) * float(t)))

o1 = math.radians(u1)
o2 = math.radians(u2)

xa = float(A) * math.cos(o1)
ya = float(A) * math.sin(o1)

xb = float(B) * math.cos(o2)
yb = float(B) * math.sin(o2)

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

print(d)

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

y=a**2+b**2-2*a*b*math.cos(x*3.14159265358979323846264/180)
print(math.sqrt(y))

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

Solution (Python):
import math
pi=3.1415926535897932
a,b,h,m=map(int,input().split())
ad=h*30+m*0.5
bd=m*6.0
x=min(abs(ad-bd),360.0-abs(ad-bd))



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

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

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

t_a = 2 * math.pi * 1.0 / 720
t_b = 2 * math.pi * 1.0 / 60

c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(((h * 60 + m) * t_a) - (m * t_b)))
print(c)

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

Solution (Python):
import math

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

minute = h * 60 + m

hourx = a * math.cos(minute / (12 * 60) * 2 * math.pi)
houry = a * math.sin(minute / (12 * 60) * 2 * math.pi)
minx = b * math.cos(minute / 60 * 2 * math.pi)
miny = b * math.sin(minute / 60 * 2 * math.pi)

print(math.sqrt((hourx - minx) ** 2 + (houry - miny) ** 2))

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

import math

s = 30*(H+M/60)
t = 6*M

r = abs(s-t)

if r>180:
  r = 360-r

a = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(r)))

print(a)

Solution (Python):
import math

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

ha = (M / 60 + H)*30
ma = M*6
ang = ha - ma

cosa =math.cos(ang*math.pi/180)

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


print(c)

Solution (Python):
from math import*


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

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

print(sqrt(a**2 + b**2 - 2 * a * b * cos(x - y)))

Solution (Python):
import sys
import math

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

kak1 = float(h * 30 + m * 0.5)
kak2 = m * 6

kaku = kak1 -kak2 if kak1 < kak2 else kak2 - kak1
result = a * a + b * b - 2 * a * b * math.cos(kaku * math.pi / 180)
print(math.sqrt(result))

Solution (Python):

import math
a,b,h,m=map(int,input().split())
x=abs(30*h+0.5*m-6*m)

y=a**2+b**2-2*a*b*math.cos(x*3.14159265358979323846264/180)
print(math.sqrt(y))

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

Solution (Python):
import math

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

hour = (H % 12) * 30 + (M / 2)
minu = M * 6

sa = abs(hour - minu)

rad = math.radians(sa)

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

print(math.sqrt(Z))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6
sa=abs(tyok-tank)
c=a**2+b**2-2*a*b*math.cos(math.radians(sa))
print(math.sqrt(c))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6
sa=abs(tyok-tank)
  
c=a**2+b**2-2*a*b*math.cos(math.radians(sa))
print(math.sqrt(c))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6
sa=0

if abs(tyok-tank)>180:
  sa=abs(tyok-tank)-360
else:
  sa=abs(tyok-tank)
  
c=a**2+b**2-2*a*b*math.cos(math.radians(sa))
print(math.sqrt(c))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6

sa=max(tyok,tank)-min(tank,tyok)
if sa>180:
  sa=sa-360
c=a**2+b**2-2*a*b*math.cos(math.radians(sa))
print(math.sqrt(c))

Solution (Python):
import math

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

si=math.radians(H*30+M/2)-math.radians(M*6)
print(math.sqrt(float(A*A+B*B)-float(2*A*B)*math.cos(si)))

Solution (Python):
import math
 
a,b,h,m = map(int, input().split())
h1 = h * 30
m1 = m * 5.5
r = abs(h1 - m1)
a1 = a ** 2
b1 = b ** 2
ab = a * b
if r == 0:
  print(abs(a-b))
elif r == 180:
  print(a + b)
elif 180 < r:
  r1 = 360 - r
  cos = math.cos(math.radians(r1))
  d = a1 + b1 - 2 * ab * cos
  ans = d ** (1/2)
  print(ans)
else:
  cos = math.cos(math.radians(r))
  d = a1 + b1 - 2 * ab * cos
  ans = d ** (1/2)
  print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6

sa=max(tyok,tank)-min(tank,tyok)

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

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







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

    
    hour_degrees = h*30 + m*0.5
    minutes_degrees = m*6

    
    if hour_degrees is minutes_degrees:
        print(abs(a - b))
        return

    
    if abs(hour_degrees - minutes_degrees) is 180.0:
        print(abs(a + b))
        return

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    


    
    degrees = abs(hour_degrees - minutes_degrees)
    
    if degrees > 180:
        degrees = 360 - degrees

    
    
    a2 = pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(degrees))

    
    print(math.sqrt(a2))

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

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    

    
    
    
    
    
    

    def test_入力例_1(self):
        input = """3 4 0 10"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 4 0 20"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3 4 0 30"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """3 4 0 40"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)
    def test_入力例_5(self):
        input = """3 4 0 50"""
        output = """5.00000000000000000000"""
        self.assertIO(input, output)



if __name__ == "__main__":
    
    resolve()

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

A, B, H, M = map(int, input().split())
ang_H = 30 * H +  0.5 * M
ang_M = 6 * M
ang = abs(ang_H - ang_M)

if abs(ang) > 180:
    ang = 360 - ang

C = A**2 + B**2 - 2*A*B*cos(radians(ang))
print(sqrt(C))