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 numpy as np

def solve(a, b, h, m):
    theta_a = 2 * np.pi * (h + m / 60) / 12
    theta_b = 2 * np.pi * m / 60
    x_a, y_a = (a * np.cos(theta_a), a * np.sin(theta_a))
    x_b, y_b = (b * np.cos(theta_b), b * np.sin(theta_b))
    return np.sqrt((x_a-x_b)**2 + (y_a-y_b)**2)

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

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

mangle = 2*pi * (m/60)
hangle = 2*pi * (h/12) + (1/6)*pi*(m/60)
dist = np.sqrt(a**2+b**2 - 2*a*b*cos(mangle- hangle))
print(dist)

Solution (Python):
import math

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

w1=2*(math.pi)/(12*60)
w2=2*(math.pi)/60
delta=abs(w1*(60*H+M)-w2*M)

r=(A**2+B**2-2*A*B*(math.cos(delta)))**0.5

print('%.20f' %(r))

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

Solution (Python):

import math


def main():
    A, B, H, M = map(int, open(0).read().split())

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

    print(ans)
    return(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math
A, B, H, M = map(int, input().split())
pi = math.pi
m = M/60
h = H/12 + m/12
theta = 2 * pi *(max(h,m) - min(h,m))
print(math.sqrt((A * math.sin(theta))**2 + (B - A * math.cos(theta))**2))

Solution (Python):
import math
a,b,h,m = map(int, input().split())
ls = 30*h+m*0.5
ss = 6*m
angle = abs(ls-ss) if abs(ls-ss)<180 else 360-abs(ls-ss)
length = (a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))**0.5
print(length)

Solution (Python):
from math import *

pi = acos(-1)
a, b, c, d = [float(x) for x in input().split()]
x1 = a * cos(c * pi / 6 + d * pi / 360)
y1 = a * sin(c * pi / 6 + d * pi / 360)
x2 = b * cos(d * pi / 30)
y2 = b * sin(d * pi / 30)
a1 = (x2 - x1) ** 2
a2 = (y2 - y1) ** 2
print(sqrt(a1 + a2))

Solution (Python):
import math

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

h = H / 12 * 360 + M / 2
m = M / 60 * 360

d = min(360 - abs(h-m), abs(h-m))
C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(d)))

print(C)

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

theta = h * 30 - m * 5.5
result = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(theta))
print(result ** (1 / 2))

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

theta = h * 30 - m * 5.5
result = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(theta))) ** (1 / 2)
print(result)

Solution (Python):
import math
A, B, H, M = map(int,input().split())
large = 6*M
small = 30*H
angle = abs(small + M/2 - large)
print(math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(angle))))

Solution (Python):
import math


def main():
    A, B, H, M = map(int, input().split())
    short_angle = math.pi * 2 * (H + M / 60) / 12
    long_angle = math.pi * 2 * M / 60
    acute_angle = min(abs(short_angle - long_angle),
                      math.pi * 2 - abs(short_angle - long_angle))
    ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(acute_angle))
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import math


def calc_clock_distance():
    numbers = input().split(' ')

    a = float(numbers[0])
    b = float(numbers[1])
    h = float(numbers[2])
    m = float(numbers[3])

    angle_s = h * math.pi / 6.0 + (m * 2.0 * math.pi / 60.0 / 12.0)
    angle_l = m * math.pi / 30.0

    angle = math.fabs(angle_s - angle_l)

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


if __name__ == '__main__':
    calc_clock_distance()

Solution (Python):
import math

def kyori(a,b,c,d):
    return math.sqrt(a**2+b**2-2*a*b*math.cos(abs(c-d)))

A, B, H, M = [int(i) for i in input().split()]
m = M* 2*math.pi/60 
h = H* 2*math.pi/12+ M*2*math.pi/60/12 



k=kyori(A,B,h,m)
print(k)

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

a,b,h,m=nm()

dh = (h+m/60)/12*360
dm = m/60*360

theta = abs(dh-dm)
if theta >= 180:
  theta = 360-theta

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

print(math.sqrt(ans))

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

a,b,h,m = [int(x) for x in stdin.readline().strip().split()]
thete_t = 360*h/12+30*m/60
thete_m = 360*m/60
diff_thete = max(thete_t, thete_m)-min(thete_t, thete_m)
thete = diff_thete if diff_thete < 180 else 360 - diff_thete
c2 = a**2 + b**2 - 2*a*b*cos(radians(thete))

print(sqrt(c2))

Solution (Python):


import math

hairu = input()
haitte = hairu.split(" ")
A = int(haitte[0])
B = int(haitte[1])
H = int(haitte[2])
M = int(haitte[3])
mKakudo = M/30*math.pi*1.0
hKakudo = H/6*math.pi + mKakudo/12
aida = abs(mKakudo - hKakudo)
nijou = A*A + B*B - 2*A*B*math.cos(aida)
print(math.sqrt(nijou))

Solution (Python):
import math

str = input().split()
a = int(str[0])
b = int(str[1])
h = int(str[2])
m = int(str[3])

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

Solution (Python):
import math

a, b, h, m = [int(arg) for arg in input().split()]
theta = abs(h * 30 + m / 2 - m * 6)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(theta))))

Solution (Python):
import math
li = list(map(int,input().split()))
pi = math.pi
a = li[0]
b = li[1]
H_th = li[2] * 30 + li[3]/2
M_th = li[3] * 6
diff = abs(H_th-M_th)
c = a**2 + b**2 -2*a*b*math.cos(diff/180*pi)
print(c**0.5)

Solution (Python):
import math
s = input().split()
a = int(s[0])
b = int(s[1])
h = int(s[2])
m = int(s[3])
th = 30*h + m/2
tm = 6*m

j = math.cos(math.radians(abs(th-tm)))

x = a**2 + b**2 -(2*a*b*j)
x = math.sqrt(x)
print(x)

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

if th>=tm:
    tbig=th
    tsml=tm
else:
    tbig=tm
    tsml=th

    
if tbig-tsml <= 180:
    print((a**2+b**2-2*a*b*math.cos(math.radians(tbig-tsml)))**(1/2))
else:
    print((a**2+b**2-2*a*b*math.cos(math.radians(360-tbig+tsml)))**(1/2))

Solution (Python):
a,b,h,m=map(int,input().split())
import math
ang=abs(5.5*m-30*h)
if ang<=180:
  ang=ang/180
else:
  ang=(360-ang)/180
ans=a**2+b**2-2*a*b*math.cos(ang*math.pi)
print(ans**(1/2))

Solution (Python):
import math
s = input("")
s = s.split(" ")
A = int(s[0])
B = int(s[1])
H = int(s[2])
M = int(s[3])
k = 360*M/60-(360*H/12+360*M/12/60)
k = abs(k)
j = math.cos(k*3.14159265359*2/360)
c = math.sqrt(A*A+B*B-2*A*B*j)
print(c)

Solution (Python):
import math
a,b,H,M=map(int,input().split())
ans=math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(abs(30*H-11*M/2))))
print(ans)

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))
rh = (h + m/60) * 30 
rm = m * 6
rd = abs(rh -rm)
print(math.sqrt((a**2) + (b**2) - (2 * a * b * math.cos(math.radians(rd)))))

Solution (Python):
import math

input_line = list(map(int, input().split(' ')))
theta = 30*input_line[2] - 5.5*input_line[3]
c = input_line[0]**2 + input_line[1]**2 - 2*input_line[0]*input_line[1]*math.cos(math.radians(theta))
print(math.sqrt(c))

Solution (Python):
import math

a, b, h, m = list(map(int, input().split()))
rh = (h + m/60) * 30 
rm = m * 6
rd = abs(rh -rm)
print(math.sqrt((a**2) + (b**2) - (2 * a * b * math.cos(math.radians(rd)))))

Solution (Python):
import math

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

d = 60 * h + m 

sh_d = 360/720*d 
lh_d = 360/60*d 


sh_x = a*math.cos(math.radians(sh_d))
sh_y = a*math.sin(math.radians(sh_d))


lh_x = b*math.cos(math.radians(lh_d))
lh_y = b*math.sin(math.radians(lh_d))

l = math.sqrt((sh_x-lh_x)**2+(sh_y-lh_y)**2)

print(l)

Solution (Python):
import math

s = list(map(int, input().split()))
rad = math.pi * 2 * (s[2] / 12.0 + (s[3] / 60.0) / 12.0 - s[3] / 60.0)
rsq = (s[0] * s[0] + s[1] * s[1]) - (2 * s[0] * s[1]) * math.cos(rad)
print(math.sqrt(rsq))

Solution (Python):

import math
a, b, h, m = map(int, input().split())
dh = float(360/12)*(h+m/60)
dm = float(360/60)*m
t = max(dh,dm)-min(dh,dm)
theta = t if t<=180 else 360-t

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

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

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

Solution (Python):
import math

a, b, h, m = map(float, input().split())
deg = abs(30.0 * h - m * 5.5)

if deg > 180.0 :
    deg = 360.0 - deg

ans = a * a + b * b - 2.0 * a * b * math.cos(deg * 4.0 * math.atan(1.0) / 180.0)
print(math.sqrt(ans))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
H_degree=(30*H+0.5*M)%360
M_degree=6*M
print((A*A+B*B-2*A*B*math.cos(math.radians(abs(H_degree-M_degree))))**0.5)

Solution (Python):
A,B,H,M=map(int,input().split())
import math
print((A**2+B**2-2*A*B*math.cos(math.radians(5.5*M-30*H)))**(1/2))

Solution (Python):
import math
ji, hun, H, M = input().split()
ji = int(ji)
hun = int(hun)
H = int(H)
M = int(M)
ji_rad = 30 * H + 0.5 * M
hun_rad = 6 * M
diff = abs(ji_rad - hun_rad)
if diff == 0:
  answer = abs(ji - hun)
elif diff == 180:
  answer = ji + hun
else:
  if diff > 180:
      diff = abs(360 - diff)
  answer = math.sqrt((ji ** 2) + (hun ** 2) - 2 * ji * hun * math.cos(math.radians(diff)))
print(answer)

Solution (Python):
import math

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

theta = 360 * abs(M / 60 - (H / 12 + M / (60 * 12)))
if theta > 180:
    theta = 360 - theta

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

Solution (Python):
import math


def main():
    a, b, h, m = map(int, input().split())
    short = m*360//60
    long = (h*360//12 + (360//12)*(m/60)) % 360
    angle = min(abs(short-long), 360-(abs(short-long)))
    
    
    ans = (pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(angle*math.pi/180))**(1/2)
    print("{: .13f}".format(ans))
    return


if __name__ == "__main__":
    main()

Solution (Python):
import math
A,B,H,M = list(map(int,input().split()))
H = H%12*30+30*(M/60)
M = M/60*360
X = max(H,M)-min(H,M)
X = min(X,360-X)
print(math.sqrt(A**2+B**2-2*A*B*math.cos(math.pi*(X/180))))

Solution (Python):
import math

num = list(map(int,input().split()))

a = num[0]
b = num[1]
h_rad = num[2]*30+0.5*num[3]
m_rad = num[3]*6
rad=0
if h_rad<m_rad:
    rad=m_rad-h_rad
else:
    rad=h_rad-m_rad

ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.pi*rad/180))
print(ans)

Solution (Python):
import math

A,B,H,M = map(int,input().split())
angH = 30.0*H+0.5*M
angM = 6.0*M
angD = abs(angH-angM)

if angD > 180.0:
    angD = 360.0-angD
cosD = math.cos(math.radians(angD))
ans2 = A*A + B*B - 2*A*B *cosD
ans = math.sqrt(ans2)
print(ans)

Solution (Python):
import math

zisin,tansin,hour,mini=map(float,input().split())
tankaku = math.radians(6*mini)
zikaku = math.radians(30*hour + 0.5*mini)

print(math.sqrt(zisin**2 + tansin**2 - 2*zisin*tansin*math.cos(tankaku-zikaku)))

Solution (Python):
import math
buf = input().split(" ")
A=int(buf[0])
B=int(buf[1])
H=int(buf[2])
M=int(buf[3])







"""
if H*5 > M:
  rad = math.radians(theta_hour-theta_min)
else:
  rad = math.radians(theta_min-theta_hour)
"""
rad=math.pi*2 *(H / 12.0 + (M / 60.0) / 12.0 - M / 60.0)
ans = math.sqrt( A**2 + B**2 - 2*A*B*math.cos(rad))
print(ans)

Solution (Python):
import math

A, B, H, M = (int(x) for x in input().split())

minuteAngle = math.pi * M / 30

hourAngle = math.pi * (H + M / 60) / 6

angleC = abs(hourAngle - minuteAngle)

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

Solution (Python):
import math

a, b, h, m = map(int, input().split())
h_angle = (h*60+m)/(12*60) * (2*math.pi)
m_angle = m / 60 * (2 * math.pi)
C = abs(m_angle - h_angle)
print("{:.10g}".format(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))))

Solution (Python):
import math
ABHM=input().split(' ')
A=int(ABHM[0])
B=int(ABHM[1])
H=int(ABHM[2])
M=int(ABHM[3])

radian=(11.0/360*M-H/6.0)*math.pi
C=abs(A**2 + B**2 -2*A*B*math.cos(radian) )**0.5
print(C)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
hm=h*5
totaldegree=0
if(hm>=m):
 
  mdegree=min((hm-m),3600-hm-m)*6
  hdegree=m/2
  totaldegree=mdegree+hdegree
else:
  mdegree=(m-hm)*6
  hdegree=m/2
  totaldegree=mdegree-hdegree

rad=math.radians(totaldegree)


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

Solution (Python):
from math import *
def solution():
    a, b, h, m  = map(int, input().split())
    return (a*a+b*b-2*a*b*cos((m*11/360-h/6)*pi))**.5
print(solution())

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

import math
p=M*360/60*math.pi/180
q=(H*60+M)/720*360*math.pi/180

L=pow(A**2+B**2-2*A*B*math.cos(p-q),0.5)
print(L)

Solution (Python):

import math


a,b,h,m = map(int,open(0).read().split())

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

x=a**2+b**2-2*a*b*math.cos(abs((ht-mt)*math.pi/180))
print(math.sqrt(x))

Solution (Python):
from math import radians,cos
a,b,h,m=map(int,input().split())
x=360-6*m
y = (12*60-h*60-m)
y=(y*360)/(12*60)
angle = abs(x-y)
ans = pow(a*a+b*b-2*a*b*cos(radians(angle)),0.5)
print(ans)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

from decimal import *





































def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007




def main():
	A,B,H,M = inputMap()

	si_ta_A = (H / 12 * 360) + (1 / 12 * 360 * M / 60)
	si_ta_B = M / 60 * 360

	si_ta = abs(si_ta_A - si_ta_B)
	

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

	print(math.sqrt(ans))





def sunuke(N, K, mod=10**9+7):
	if N < K or K-1 < 0:
		return 0
	else:
		return combination(N-1, K-1, mod)




def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y



def H(n, r, mod=10**9+7):
	
	
    return combination(n+r-1, r, mod)


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv



def dfs(graph,parent,counter,edge):
    stk = []
    stk.append(edge)
    while len(stk) > 0:
        p = stk.pop()
        for e in graph[p]:
            if parent[p] == e:
                continue
            else:
                parent[e] = p
                counter[e] += counter[p]
                stk.append(e)



if __name__ == "__main__":
	main()

Solution (Python):


import math


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

  mx = B * math.sin(math.pi * M / 30)
  my = B * math.cos(math.pi * M / 30)

  hx = A * math.sin(math.pi * (H * 60 + M) / 360)
  hy = A * math.cos(math.pi * (H * 60 + M) / 360)

  print(math.sqrt((mx - hx) ** 2 + (my - hy) ** 2))


if __name__ == '__main__':
  main()

Solution (Python):
import math
a, b, h, m  = map(int, input().split())
theta = (h * 60 * 0.5+ m * 0.5) % 360 - (h * 60 * 6 + m * 6) % 360

if theta > 180:
    theta = 360 - theta

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

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

theta_l = 2 * math.pi * M /60
theta_s = 2 * math.pi * (H/12 + M/720)
theta = theta_l - theta_s

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

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

cho = 6*M
tan = 30*(H+M/60)

angle = abs(cho-tan)
answer = math.sqrt(A*A+B*B-2*A*B*math.cos(angle/180*math.pi))
print(answer)

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

minute = h * 60 + m
short = minute * (1/2)
long = m * 6

degree = min(abs(short-long), abs(short-360-long))

c = (a**2 + b**2 - 2 * a * b * math.cos(degree/180 * math.pi)) ** (1/2)

print(c)

Solution (Python):
import math





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


H_angle = H * 30 + (M / 60 * 30)

M_angle = M * 6


H_M_angle = abs(H_angle - M_angle)

cosHM = math.cos(math.radians(H_M_angle))

C2 = A**2 + B**2 - 2*A*B*cosHM

print(math.sqrt(C2))

Solution (Python):
A,B,H,M=map(int,input().split())
import math
Q=math.cos(((math.pi/30)-(math.pi/360))*(60*H+M))

r=math.sqrt(A*A+B*B-2*A*B*Q)
print(r)

Solution (Python):
short , long , hour1 , mini = map(int, input().split())
hour2 = hour1 + mini / 60
import math
shortx = short * math.sin(math.radians( hour2 * 30 ))
shorty = short * math.cos(math.radians( hour2 * 30 ))
longx = long * math.sin(math.radians( mini * 6 ))
longy = long * math.cos(math.radians( mini * 6 ))
c = math.sqrt((shortx - longx) ** 2 + (shorty - longy) ** 2 )
print(c)

Solution (Python):
import math

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

dTan=30*H+30*(M/60)
dCho=6*M
angle=abs(dTan-dCho)

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

Solution (Python):
import math

A,B,H,M = map(int,input().split())
H_angle = (H*60+M)*360/(12*60)
M_angle = M*360/60
angle = min(abs(H_angle-M_angle),360-abs(H_angle-M_angle))
ans = (A**2+B**2-(2*A*B*math.cos(math.radians(angle))))**0.5

print(ans)

Solution (Python):
import math

input_line=input()
num=input_line.split()

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

kakudo = abs(M*6 - (H*30+0.5*M))
if kakudo >= 180:
    kakudo = 360 - kakudo
kosainn = math.cos(math.radians(kakudo))


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

Solution (Python):
import math

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

a  = M / 60 * 2 * p
b = (H * 60 + M )/(60*12) * 2 * p

result = (A**2 + B**2 - 2* A*B*math.cos(a-b) )**0.5

print(result)

Solution (Python):
from math import *
a,b,h,m = map(int, input().split())
h = h + m/60
theta_h = (h / 12) * 2 * pi
theta_m = (m / 60) * 2 * pi

distance = (a * cos(theta_h) - b * cos(theta_m))**2 + (a * sin(theta_h) - b * sin(theta_m))**2
print(sqrt(distance))

Solution (Python):
from math import *
a,b,h,m = map(int, input().split())
h = h + m/60
theta_h = (h / 12) * 2 * pi
theta_m = (m / 60) * 2 * pi

distance = (a * cos(theta_h) - b * cos(theta_m))**2 + (a * sin(theta_h) - b * sin(theta_m))**2
print(sqrt(distance))

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

h_rot = np.pi / 2 - (np.pi * (H * 30 + M / 2) / 180 )
m_rot = np.pi / 2 - np.pi * (6 * M) / 180 

x_diff = (A * np.cos(h_rot) - B * np.cos(m_rot)) ** 2
y_diff = (A * np.sin(h_rot) - B * np.sin(m_rot)) ** 2

print(np.sqrt(x_diff + y_diff))

Solution (Python):
import math

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

A_kaku = 360*H/12 + 30*M/60
B_kaku = 360*M/60
sa_kaku = abs(A_kaku - B_kaku)

math.cos(math.radians(sa_kaku))

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

Solution (Python):



from math import *
from copy import *					
from heapq import *					
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize				
from operator import *				
from itertools import *				
from collections import Counter		
from collections import defaultdict 

'''
3 4 9 0
'''

def cosineRule(b,c,theta):
	a = b**2 + c**2 - 2*b*c*cos(theta)
	return sqrt(a)

def solve(l):
	b,c,h,m = l
	hh = h*30 + (m/60)*30
	mm = m*6
	theta = min(abs(hh-mm),360-abs(hh-mm))
	theta = pi*theta/180
	a = cosineRule(b,c,theta)
	return a
	
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print("%.20f" % ans)

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

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

Solution (Python):
import sys, math

max_int = 1000000001  
min_int = -max_int

a, b, h, m = map(int, sys.stdin.readline().split())

alpha = abs(math.pi * (h / 6 + m / 360 - m / 30))
if alpha > math.pi:
    alpha = 2 * math.pi - alpha

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

Solution (Python):
import sys
import math
DH = {i: i * 30 % 360 for i in range(12)}
DM = {i: i * 5.5 % 360 for i in range(60)}
A,B,H,M = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
RH = DH[H]
RM = DM[M]
D = max(RH - RM, RM - RH)
C = min(D, 360 - D)
Y = math.pi * (C / 180.0)
a = math.sqrt((A ** 2) + (B ** 2) - ((2 * A * B) * math.cos(Y)))
print(a)

Solution (Python):
import math

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



kakudo = abs(H * 30 + M * 0.5 - M * 6)
if kakudo >= 180:
    kakudo = 360 - kakudo
AAA = A * A + B * B - 2 * A * B * math.cos(math.radians(kakudo))


C = math.sqrt(AAA)
print(C)

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


h = H * 30 + 0.5 * M
m = 6 * M
hh = abs(h - m)
mm = 360 - hh

if hh <= mm:
    c = hh
else:
    c = mm

c = math.radians(c)

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

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

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


h = H * 30 + 0.5 * M
m = 6 * M
hh = abs(h - m)
mm = 360 - hh

if hh <= mm:
    c = hh
else:
    c = mm

c = math.radians(c)

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

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

Solution (Python):
import sys
import math

input = sys.stdin.readline
sys.setrecursionlimit(4100000)


def main():
    A, B, H, M = map(int, input().rstrip().split())
    theta_m = 2 * math.pi * M / 60
    theta_h = 2 * math.pi * (H * 60 + M) / (12 * 60)
    theta = abs(theta_m - theta_h)
    if theta > math.pi:
        theta = 2 * math.pi - theta
    ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
    
    
    
    print('{:.20f}'.format(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

c = abs(h * 30 - m * 6 + m * 0.5)

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

Solution (Python):
import math
a,b,c,d=map(int,input().split())
angle=abs(60*c-11*d)/2
angle=min(angle,360-angle)
print(math.sqrt((a*a)+(b*b)-2*b*a*math.cos((angle*math.pi)/180)))

Solution (Python):
import math

Input_list = [int(i) for i in input().split()]
A = Input_list[0]
B = Input_list[1]
H = Input_list[2]
M = Input_list[3]

A_angle = 2 * math.pi * (H + M/60.0) / 12.0
B_angle = 2 * math.pi * M / 60.0

R_A = [A*math.cos(A_angle), A*math.sin(A_angle)]
R_B = [B*math.cos(B_angle), B*math.sin(B_angle)]

L = ((R_A[0] - R_B[0])**2 + (R_A[1] - R_B[1])**2) ** 0.5
print(L)

Solution (Python):
from math import *

def get(R, T):
	T /= 180
	T *= pi
	x = 0
	y = R
	return x * cos(T) - y * sin(T), x * sin(T) + y * cos(T)

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

H += M / 60;

x1, y1 = get(A, H * 30)
x2, y2 = get(B, M * 6)

print('%0.12f'%(((x1-x2) ** 2 + (y1-y2) ** 2) ** 0.5))

Solution (Python):
import math




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










ang1=360*(h/12)+30*m/60
ang2=360*m/60
ang=abs(ang1-ang2)

if ang>=180.0:

    ang=360.0-ang



ans = a**2 + b**2 - 2.0*a*b*math.cos(math.pi*ang/180.0)
ans = math.sqrt(ans)


print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h*=30
h+=m/2
m*=6
t=min(abs(m-h),360-abs(m-h))
p=math.pi*(t/180)

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

Solution (Python):
import math

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

kakudo = abs((H*30+0.5*M-M*6)) 

if kakudo >= 180:
    kakudo = 360 - kakudo

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

Solution (Python):
import math

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

ang1 = 360*H/12+30*M/60
ang2 = 360*M/60

x1=B*math.cos(math.radians(ang1))
y1=B*math.sin(math.radians(ang1))

x2=A*math.cos(math.radians(ang2))
y2=A*math.sin(math.radians(ang2))

l=((abs(x1-x2))**2+(abs(y1-y2))**2)**(1/2)

print(l)

Solution (Python):
import math
a,b,h,m=input().split()
a=float(a)
b=float(b)
h=float(h)
m=float(m)
pi=math.pi
rad=2*pi*(h/12+m/60/12-m/60)
s1=2*pi*(h/12+m/60/12)
s2=2*pi*m/60
x1=math.cos(s1)*a
y1=math.sin(s1)*a
x2=math.cos(s2)*b
y2=math.sin(s2)*b
ans=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)
print(math.sqrt(ans))

Solution (Python):
import math
import cmath

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

a = cmath.rect(A, 2 * math.pi * ((H + M / 60) / 12))
b = cmath.rect(B, 2 * math.pi * (M / 60))

print(abs(a - b))

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

Solution (Python):
import math

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

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

X = A*math.cos(alpha) - B*math.cos(beta)
Y = A*math.sin(alpha) - B*math.sin(beta)

print(math.sqrt(X*X + Y*Y))

Solution (Python):
import math
A,B,H,M = map(int,input().split()) 
deg_M = 2*M*math.pi / 60
deg_H = ((H + M/60)/12) * 2 * math.pi

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

Solution (Python):
import math

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

deg_h = 360 / 12
deg_m = 360 / 60

H = h * deg_h + m * (deg_h/60)
M = m * deg_m
deg = abs(H - M)

if deg > 180:
    deg = 360 - deg

rad = (deg/180) * math.pi
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(rad))
print(c)

Solution (Python):
import math
def resolve():
    A, B, H, M = map(int, input().split())
    
    deg_H = 360/12
    
    deg_M = 360/60

    hr = deg_H*H + (deg_H/60)*M
    mr = deg_M*M
    deg = abs(hr-mr)
    if deg>180:
        deg = 360- deg

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

if __name__ == "__main__":
    resolve()

Solution (Python):
import math

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

H_angle = 30*H + 0.5*M 
M_angle = 6*M          
HM_angle = abs(H_angle - M_angle)

if HM_angle == 0:
    print(abs(A-B))
elif HM_angle == 180:
    print(A+B)
else:
    print((A**2 + B**2 - 2*A*B*math.cos(math.radians(HM_angle)))**0.5)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
theta = M * math.pi / 30 - H * math.pi / 6 - M * math.pi / 360

C_2 = A ** 2 + B ** 2 - 2*A*B*math.cos(theta)
C = C_2 ** (1/2)
print(C)

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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
x1=30*h+0.5*m
x2=6*m
x=x1-x2
cosx=math.cos(math.radians(x))
c=math.sqrt(a**2 + b**2 -2 * a * b * cosx)
print(c)

Solution (Python):


import math


def main():
    A, B, H, M = map(int, input().split())
    print((A**2 + B**2 - 2 * A * B *
           math.cos(math.radians(H * 30 + M * (1 / 2 - 6))))**0.5)


if __name__ == "__main__":
    main()

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

Solution (Python):
import math
a, b, h, m = [int(i) for i in input().split()]
ka = 30 * h + 0.5 * m
kb = 6 * m
if ka > kb:
    ka, kb = kb, ka
    a, b = b, a
diff = min(kb - ka, 360 - kb + ka)
diff = math.pi * (diff / 180)
r = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(diff))

print(r)

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


arg_b = math.pi * float(M) / 30
arg_a = (math.pi / 6) * (float(H) + float(M)/60) 
K = abs(arg_b - arg_a)
C = math.sqrt(A*A+B*B - 2*A*B*math.cos(K))
print(C)

Solution (Python):
import numpy as np
data = input().split()
data = [int(d) for d in data]

t = data[2] + data[3]/60

A = data[0] * np.array([np.cos(2*np.pi*t), -np.sin(-2*np.pi*t)])
B = data[1] * np.array([np.cos(np.pi*t/6), -np.sin(-np.pi*t/6)])

d = np.sqrt(np.sum((A-B)**2))

print(d)

Solution (Python):
import math
 
PI = math.pi
A, B, H, M = map(int, input().split())
 
arg_a = (float(H) + float(M)/60) / 12.0 * 360
arg_b = float(M) / 60.0 * 360
 
 
C = math.sqrt(A*A + B*B - 2*A*B* math.cos((arg_a-arg_b)/360*2*PI))
print(C)

Solution (Python):
import math
 
PI = math.pi
A, B, H, M = map(int, input().split())
 
arg_a = (float(H) + float(M)/60) / 12.0 * 360
arg_b = float(M) / 60.0 * 360
 
 
C = math.sqrt(A*A + B*B - 2*A*B* math.cos((arg_a-arg_b)/360*2*PI))
print(C)

Solution (Python):
import math
cin = input()
A = cin.split(' ')[0]
B = cin.split(' ')[1]
H = cin.split(' ')[2]
M = cin.split(' ')[3]

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

mx = int(A) * math.cos(theta_m) 
my = int(A) * math.sin(theta_m)
hx = int(B) * math.cos(theta_h) 
hy = int(B) * math.sin(theta_h)

dist = math.sqrt((mx-hx)**2 + (my-hy)**2)

print(dist)

Solution (Python):
import math

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

arg_a = (float(H) + float(M)/60) / 12.0 * 360
arg_b = float(M) / 60.0 * 360




C = math.sqrt(A*A + B*B - 2*A*B* math.cos(math.fabs(arg_a-arg_b)/360*2*PI))
print(C)