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 sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10**7)

ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

import math

a, b, h, m = na()

ah = h * 30 + m * 0.5
am = m * 6
ang = abs(ah - am)
t = abs(360 - ang)
print("{:.10f}".format(math.sqrt(pow(a, 2) + pow(b, 2) - (2 * a * b * math.cos(math.radians(t))))))

Solution (Python):
from math import cos
from math import radians
a,b,h,m=map(int,input().split())
alpha=(h*60+m)/2
beta=6*m
n=radians(min(abs(alpha-beta),360-abs(alpha-beta)))
ans=(a**2+b**2-2*a*b*cos(n))**(1/2)
print(ans)

Solution (Python):
import math
a_h, b_m, hour, minute = map(int, input().split(" "))
pi = math.pi
arg_h = (hour + minute/60) * 360/12
arg_m = minute * 360/60

diff_arg = abs(arg_h - arg_m)
ans_square = a_h**2 + b_m**2 - 2 * a_h * b_m * math.cos(math.radians(diff_arg)) 
ans = math.sqrt(ans_square)
print(ans)

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

Hs= H*30+0.5*M
Ms= M*6
s=abs(Ms-Hs)
result=A*A + B*B - 2*A*B*math.cos(math.radians(s))
print(math.sqrt(result))

Solution (Python):



import math


if __name__ == '__main__':
    
    A, B, H, M = list(map(float, input().split()));
    
    angle = ((30*H)+(0.5*M))-6*M;
    cosine = math.cos(math.radians(angle));
    
    answer = math.sqrt(pow(A,2)+pow(B,2)-2*A*B*cosine);
    print(answer);

Solution (Python):
import sys
input = sys.stdin.readline
import math
def colon(a,b,h,m):
    urh = 0.5
    urm = 6
    hmr = (h * 60) * urh + m * urh
    mr = m * urm
    ay = a * math.sin(math.radians(hmr))
    ax = a * math.cos(math.radians(hmr))
    by = b * math.sin(math.radians(mr))
    bx = b * math.cos(math.radians(mr))
    
    ans = math.sqrt((ay - by) ** 2 + (ax - bx) ** 2)
    print(ans)
    
if __name__ == "__main__":
    a,b,h,m = map(int,input().split())
    colon(a,b,h,m)

Solution (Python):
import numpy as np
para = str(input()).split()
hour = int(para[2])
minute = int(para[3])

angleH = (30 * hour + 30 * (minute/60))
angleM = (minute/60) * 360
angle = abs(angleM-angleH)
rad = angle * np.pi / 180
cosR = np.cos(rad)
l1 = int(para[0])
l2 = int(para[1])
line = np.sqrt(l1 * l1 + l2 * l2 - 2*l1*l2*cosR)
print(line)

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

a, b, h, m = map(int, input().split())
mm = m / 60 * 360
hh = h / 12 * 360 + m / 60 * 30
theta = min(abs(mm - hh), 360 - abs(mm - hh))
c = a * a + b * b - 2 * a * b * math.cos(theta * math.pi / 180)
print(c**0.5)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
ah=30*h+m/2
am=6*m
the=max(ah,am)-min(ah,am)
if the>180:
    the=360-the
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(the))))

Solution (Python):
from math import factorial as fact
import math
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
from collections import deque



def input1():
	return int(input())


def input2():
	return map(float,input().split())


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

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

def combinations(n,r):
	return list(itertools.combinations(range(n),r))



def all_sets(num_list):
	subsets=[]
	for i in range(2,len(num_list) + 1):
		for c in combinations(num_list, i):
			subsets.append(c) 
	return subsets


def ch(x1):
	cf=[]
	for i in range(2,math.sqrt(x1)+1):
		if x1 % i==0:
			cf.append(i)
	return cf

def CountOneRoots(x,y):
	
	return fact(x+y)/fact(x)/fact(y)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
	
def count_str(m):
	tmp={}
	for i in range(10):
		if i in tmp:
			tmp[i]=1
		else:
			tmp[i]+=1
	return tmp

def is_prime(n):
	if n==1: return True

	for i in range(2,int(math.sqrt(n))+1):
		if n%i==0:
			return False
	return True


a,b,h,m=input2()
m_new=m/5.0
shita=abs((h+m/60 - m_new))*30
cos_shita= math.radians(shita)
result=a**2+b**2-2*a*b*math.cos(cos_shita)

print(math.sqrt(result))

Solution (Python):
import math

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

rad = 0
deg_long = M * 6
deg_short = 30 * H + M / 2

print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(abs(deg_long - deg_short)))))

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
 
deg_long = M * 6
deg_short = 30 * H + M / 2
    
rad = math.radians( min(deg_long - deg_short, 360-(deg_long-deg_short)))
print( math.sqrt(A **2 + B ** 2 - 2* A * B* math.cos(rad)) )

Solution (Python):
import math

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

rad = 0
deg_long = M * 6
deg_short = 30 * H + M / 2

if abs(deg_long - deg_short) > 180:
    rad = math.radians(360 - abs(deg_long - deg_short))
else:
    rad = math.radians(abs(deg_long - deg_short))

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

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

minutes=H*60+M

A_angle=360*minutes/(12*60)
A_angle=A_angle%360
B_angle=M*6
A_rad=math.radians(A_angle)
B_rad=math.radians(B_angle)
dlt_rad=abs(A_rad-B_rad)
C=math.sqrt(A**2+B**2-2*A*B*math.cos(dlt_rad))
print(C)

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

Solution (Python):
import numpy as np
import math

def deg(rad):
    return (360 / 2 * np.pi) * rad
a,b,h,m = map(int, input().split(" "))


hn = ((h/12) + (m/60)/12) * 360
mn = (m/60) * 360








c = a**2 + b**2 - 2*a*b*math.cos(math.radians(hn - mn))

ans = c ** 0.5
print(ans)

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

Solution (Python):







import math
A,B,H,M = map(int,input().split())
H += (M/60)
hx = A*math.sin(math.radians(30*H))
hy = A*math.cos(math.radians(30*H))
mx = B*math.sin(math.radians(6*M))
my = B*math.cos(math.radians(6*M))
distans = math.sqrt((hx-mx)**2 + (hy - my)**2)
print(distans)

Solution (Python):
import math

L ,S, t, m = map(int, input().split())
T=(t/12)*360+(m/60)*360/12
M=(m/60)*360
rd=abs(T-M)
ans=L**2+S**2-(2*L*S*math.cos(math.radians(rd)))
print(math.sqrt(ans))

Solution (Python):
from math import pi,cos,sqrt
a,b,h,m = map(int,input().split())
minutes = h*60 + m
Dh = minutes * 0.5 % 360
Dm = minutes * 6 % 360
arg = abs(Dh-Dm)*pi/180
print(sqrt(a**2 + b**2 - 2*a*b*cos(arg)))

Solution (Python):
import math

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


rad_h = h * 60 + m
rad_m = m * 12
diff_rad = abs(rad_h - rad_m)


c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(diff_rad/720*2*math.pi))
print(c)

Solution (Python):
def C():
    a,b,h,m = list(map(int, input().split()))
    import math
    h_r = 2*math.pi*(h+m/60)/12
    m_r = 2*math.pi*m/60
    r = abs(h_r-m_r)
    print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r)))
C()

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

h_deg = H*30 + M*0.5
m_deg = M*6
rad = math.radians(abs(h_deg - m_deg))


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

Solution (Python):
def C():
    a,b,h,m = list(map(int, input().split()))
    import math
    h_r = 2*math.pi*(h+m/60)/12
    m_r = 2*math.pi*m/60
    r = abs(h_r-m_r)
    print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(r)))
C()

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

hw = 360 * (h/12) + 30 * m/60
mw = 360 * (m/60)
ans=0

w = abs(hw-mw)

if w > 180:
  w = 360 - w
elif w == 180:
  ans = a+b


if w == 90:
  ans = math.sqrt(a**2 + b**2)

 
else:
  ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(w)))

print(ans)

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

print((a**2+b**2-(2*a*b*math.cos(math.radians(h*30 - m*5.5))))**0.5)

Solution (Python):
import math

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

Ad = H * 30 + M * 0.5
Bd = M * 6

powans = A*A + B*B - (2*A*B*math.cos(math.radians(Ad-Bd)))
print(math.sqrt(powans))

Solution (Python):
import numpy as np

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

short_angle = 360*(1-(H+M/60)/12)
long_angle = 360*(1-M/60)

angle=abs(short_angle-long_angle)

if angle > 180:
    angle =360-angle
    


ans_2=A**2+B**2-2*A*B*np.cos(np.pi*angle/180)
ans=np.sqrt(ans_2)

print(ans)

Solution (Python):
import math

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

long_degree=(math.pi/30*(60*H+M))%(2*math.pi)
short_degree=(math.pi/360*(60*H+M))%(2*math.pi)

degree=long_degree-short_degree
C=math.sqrt(A*A+B*B-2*A*B*math.cos(degree))

print(C)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
d = 2*math.pi*(60*h+m)/720
g = 2*math.pi*m/60
l = pow(a**2+b**2-2*a*b*math.cos(g-d),1/2)
print(l)

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

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

def main():
    a,b,h,m=map(int,input().split())
    ang=calcAngle(h,m)
    dist=sqrt(abs(a*a+b*b-2*a*b*cos(radians(ang))))
    print(dist)

main()

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

pi = acos(-1)
a, b, h, m = map(float, input().split())

theta_h = pi * 2 * (h + m / 60) / 12
theta_m = pi * 2 * m / 60

h_x = cos(theta_h) * a
h_y = sin(theta_h) * a

m_x = cos(theta_m) * b
m_y = sin(theta_m) * b

print(((h_x - m_x) ** 2 + (h_y - m_y) ** 2) ** 0.5)

Solution (Python):
import math
a,b,h,m = map(int, input().split())
atheta = 2*math.pi*(60*h+m)/720
btheta = 2*math.pi*m/60
l = pow(a**2+b**2-2*a*b*math.cos(btheta-atheta),1/2)
print(l)

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD
combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''
"
def gcd(a, b):
    while b:
        
        
        a, b = b, a % b
    return a

"
def lcm(a, b):
    return a * b // gcd (a, b)

"
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table











'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')


print('abc', end='')
print('xyz')

source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    
    
    
    a,b,h,m=map(int, input().split(" "))
    jj=h//12
    hrad=30*(h-12*jj)+30*(m/60)
    mrad=360*(m/60)
    theat=min(max(hrad,mrad)-min(hrad,mrad),360-max(hrad,mrad)+min(hrad,mrad))
    
    

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


    
    
     

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')
    
    
    
    

    
        
    
    

    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    
    



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Solution (Python):
import math
A,B,H,M = map(int, input().split())
X = H*30+M*0.5
Y = M*6
if  -180 < X - Y < 0:
  z = Y - X
elif X - Y <= -180:
  z = 360 -(Y - X)
elif 180 > X - Y >= 0:
  z = X - Y
elif X - Y >= 180:
  z = 360-(X - Y)
ans = A*A+B*B-2*A*B*math.cos(math.radians(z))
ANS = math.sqrt(ans)

print(ANS)

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

s = abs((h/12) * 360 + 30 *(m/60) - (m/60) * 360)
R = min(360 - s, s)
ans = (a**2 + b**2 - 2*a*b*math.cos(math.radians(R)))**(1/2)
print(ans)

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

Solution (Python):
import math
A,B,H,M=map(int,input().split())
thetaA=360/12*H+360/12*M/60
thetaB=360/60*M
theta=thetaA-thetaB
print(math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(theta))))

Solution (Python):
import math
 
A, B, H, M = map(int, input().split())
angleA = 30 * H + 30 / 60 * M
angleB = 360 / 60 * M
x = abs(angleA - angleB)
if x > 180:
    x = 360 - x
l = math.sqrt(A * A + B * B - 2 * A * B * math.cos(math.radians(x)))
print(l)

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

import math

pi = math.pi
omegah = (2 * pi) / (12 * 60)   
omegam = (2 * pi) / 60 
time_min = h * 60 + m
radh = omegah * time_min
radm = omegam * m
if abs(radh - radm) <= pi:
    rad_def = abs(radh - radm)
else:
    rad_def = 2 * pi - abs(radh - radm)

def lcos(p, q, theta):
    r = math.sqrt(p**2 + q**2 - 2*p*q*math.cos(theta))
    return r

c = lcos(a, b, rad_def)
print(c)

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




tyousin = M*360/60

tansin = H*360/12 + M*360/60/12
 
kakudosa = tyousin - tansin


result_root = A**2 + B**2 - 2*A*B*math.cos(math.radians(kakudosa))

print(math.sqrt(result_root))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
 
tyousin = M*360/60
tansin = H*360/12 + M*360/60/12
 
kakudosa = tyousin - tansin

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

Solution (Python):
import math

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

deg = 0
deg += 5.5 * M
deg -= 30 * H

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

Solution (Python):
import sys
import math


def main():
    read = lambda: sys.stdin.readline().rstrip()
    
    
    A,B,H,M=map(int, input().split())
     
    a=math.pi*(H+M/60)/6
    b=math.pi*M/30
     
    s=abs(a-b)
     
    C=math.sqrt(A**2+B**2-2*A*B*math.cos(s))
     
    print(C)
 
if __name__ == "__main__":
    main()

Solution (Python):
import math

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

deg = 0

deg += 5.5 * m
deg -= 30 * h

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

Solution (Python):
import math

A, B, H, M = map(int, input().split())
angleA = 30 * H + 30 / 60 * M
angleB = 360 / 60 * M
x = abs(angleA - angleB)
if x > 180:
    x = 360 - x
l = math.sqrt(A * A + B * B - 2 * A * B * math.cos(math.radians(x)))
print(l)

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

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

    
    minute_deg = 6 * m

    
    hour_deg = 30 * (h + m / 60)

    
    deg_diff = abs(minute_deg - hour_deg)

    
    ans_squared = a ** 2 + b ** 2 - 2 * a * b * cos(radians(deg_diff))
    print(sqrt(ans_squared))
    
resolve()

Solution (Python):

import math
a,b,h,m=map(int,input().split())
deg=((h+m/60)/12-m/60)*2*math.pi
res=math.sqrt(a**2+b**2-2*a*b*math.cos(deg))
print(res)

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

thun = M / 60 * 2 * math.pi
tzi = (60 * H + M)/ 720 * 2 * math.pi

chun = [B * math.cos(thun), B * math.sin(thun) ]
czi = [A * math.cos(tzi), A * math.sin(tzi) ]

print( ( (chun[0]-czi[0])**2 + (chun[1]-czi[1])**2 )**0.5 )

Solution (Python):
import math

a, b, h, m = map(int, input().split())
angle = 30*h - 5.5*m
if(angle >= 180):
  angle = 360 - angle
print((a**2+b**2-(2*a*b*math.cos(math.radians(angle))))**0.5)

Solution (Python):
import math

def main():
    a, b, h, m = map(int, input().split())
    hr = 360 / 12 * (h + m / 60)
    mr = 360 / 60 * m
    if hr == 0:
        hr = 360
    if mr == 0:
        mr = 360
    diff = min(abs(hr - mr), abs(hr - mr))
    
    print('{:.10f}'.format(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(diff)))))
if __name__ == '__main__':
    main()

Solution (Python):
import math

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

hm = H + M / 60
h = hm * 30
m = M * 6

sa = abs(h - m)
ans = (A**2 + B**2 - A * B * math.cos(math.radians(sa)) * 2) ** 0.5








print(ans)

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

def polar2euclidean(r, theta):
    x = r * cos(theta)
    y = r * sin(theta)
    return x, y

A, B, H, M = map(int, input().split())
x1, y1 = polar2euclidean(A, -(H * 60 + M) / 720 * 2 * pi)
x2, y2 = polar2euclidean(B, -M / 60 * 2 * pi)
ans = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print(ans)

Solution (Python):
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
import math
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()







abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007

inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1] 
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1
def powerMod(x,y,p):
    res=1
    x%=p
    while y>0:
        if y&1:
            res=(res*x)%p
        y=y>>1
        x=(x*x)%p
    return res
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x
def isPrime(n):
    if(n<=1): return False
    if(n<=3): return True
    if(n%2==0 or n%3==0): return False
    i=5
    while(i*i<=n) : 
        if(n%i==0 or n%(i+2)==0) : 
            return False
        i=i+6
    return True
def read():
    sys.stdin = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 

def main():
    a,b,h,m=map(int,input().split())
    mdeg=m*6
    hdeg=h*30
    totdeg=hdeg+(mdeg/360)*30
    totdeg=totdeg-mdeg
    print("%.20f"%math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(totdeg))))
    
    
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    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(b"\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()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    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()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(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())
aH=30*H+0.5*M
aM=6*M
r=abs(aH-aM)
a=A*A+B*B-2*A*B*math.cos(math.radians(r))
print(a**0.5)

Solution (Python):
import math

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

theta_m = (math.pi * 2 * (M/60)) 
theta_h = (math.pi * 2 * (H/12)) + (math.pi/6 * (M/60))

theta = abs(theta_h - theta_m)

Ax, Ay = A *  math.cos(theta), A * math.sin(theta)
Bx, By = B, 0.0

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

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


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

M = h*60 + m
theta = abs(math.pi*M/360 - math.pi*M/30)
theta = min(360-theta,theta)

print(c(theta))

Solution (Python):
import sys

sys.setrecursionlimit(10000000)
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue



ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, H, M = il()
    hc = H * 30 + 0.5 * M
    mc = 6 * M
    C = abs(hc - mc)
    print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(C))))


if __name__ == '__main__':
    main()

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

Solution (Python):


import math

L = [int(i) for i in input().split()]
A=L[0]
B=L[1]
H=L[2]
M=L[3]
H_deg=(H/12)*360+(M/60)*30
M_deg=(M/60)*360
if abs(H_deg-M_deg)>abs(M_deg-H_deg):
    deg=abs(M_deg-H_deg)
else:
    deg=abs(H_deg-M_deg)

AN=A*A+B*B-2*A*B*math.cos(math.radians(deg))
ANS=math.sqrt(AN)
print('{:.9f}'.format(ANS))

Solution (Python):
import numpy as np

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

time = H*60 + M

np.pi
omega_A = 2.0*np.pi/(12.0*60.0)
omega_B = 2.0*np.pi/60.0

theta_A = omega_A * time
theta_B = omega_B * time

x_A = A * np.sin(theta_A)
y_A = A * np.cos(theta_A)

x_B = B * np.sin(theta_B)
y_B = B * np.cos(theta_B)

distance = np.sqrt((x_A - x_B)**2.0 + (y_A - y_B)**2.0)
print(distance)

Solution (Python):
import math

A,B,H,M= list(map(int, input().split()))
 
theta = 2*math.pi*H/12+2*math.pi*M/12/60 
phi = 2*math.pi*M/60 
  
C = math.sqrt(A**2+B**2-2*A*B*math.cos(theta-phi))
print(C)

Solution (Python):
import math
'''
時針：Aセンチ，12時間で1周
分針：Bセンチ，1時間で1周
0時ちょうどに針は重なっていた．H時M分のとき，2本の針の端点は何センチ離れているか．
'''
 
A,B,H,M= list(map(int, input().split()))
 
theta = 2*math.pi*H/12+2*math.pi*M/12/60 
phi = 2*math.pi*M/60 
  
C = math.sqrt(A**2+B**2-2*A*B*math.cos(theta-phi))
print(C)

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

Solution (Python):
import math

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

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

Solution (Python):
import math

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

  angle_per_hour = 360 / 12
  angle_per_minute = 360 / 60

  angle_hour_hand = math.radians(H * angle_per_hour + M * (angle_per_hour / 60))
  angle_minute_hand = math.radians(M * angle_per_minute)

  hour_x = A * math.cos(angle_hour_hand)
  hour_y = A * math.sin(angle_hour_hand)
  minute_x = B * math.cos(angle_minute_hand)
  minute_y = B * math.sin(angle_minute_hand)

  dx = hour_x - minute_x
  dy = hour_y - minute_y

  print(math.sqrt(dx ** 2 + dy ** 2))


if __name__ == "__main__":
  main()

Solution (Python):


import math


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


tmp_1 = H * 30 + 0.5 * M
tmp_2 = 6 * M
tmp_3 = min(abs(tmp_1-tmp_2), 360-abs(tmp_1-tmp_2))
radian = math.radians(tmp_3)
tmp_4 = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(radian))


print(tmp_4)

Solution (Python):
import math
def calcAngle(h,m): 
          
        
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
        
        
        
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
        
        angle = abs(hour_angle - minute_angle) 
          
        
        
        angle = min(360 - angle, angle) 
          
        return angle
a,b,h,m=map(int,input().split())
angle=calcAngle(h,m)
angle*=(math.pi/180)
ans=(a**2+b**2-(2*a*b*math.cos(angle)))**0.5
print('%.20f'%ans)

Solution (Python):
import math

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

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

kakudo = abs(h-m)

kakudo = math.radians(kakudo)

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