Problem:
 Score: 300 points    Problem Statement  Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively.  An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively.  At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?      Constraints   All values in input are integers.  1 \leq A, B \leq 1000  0 \leq H \leq 11  0 \leq M \leq 59         Input  Input is given from Standard Input in the following format:  A  B  H  M       Output  Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9} .        Sample Input 1 3 4 9 0      Sample Output 1 5.00000000000000000000  The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters.        Sample Input 2 3 4 10 40      Sample Output 2 4.56425719433005567605  The two hands will be in the positions shown in the figure below. Note that each hand always rotates at constant angular velocity.

Solution (Python):
import math

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

h = h * 60 

a_angle = (pi/360) * (h + m)
b_angle = (pi/30) * (h + m)
ab_angle = abs(a_angle - b_angle)

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

Solution (Python):

"""AtCoder Beginner Contest 168: C
https://atcoder.jp/contests/abc168/tasks/abc168_c
"""

__author__ = 'bugttle <bugttle@gmail.com>'

import math

def normalize_angle(angle):
    angle = 360 - angle
    angle = angle + 90
    if (360 <= angle):
        angle -= 360
    return angle


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

    
    
    angle = normalize_angle((H * 30 + M * 0.5))
    x1 = A * math.cos(math.radians(angle))
    y1 = A * math.sin(math.radians(angle))

    
    angle = normalize_angle((M * 6))
    x2 = B * math.cos(math.radians(angle))
    y2 = B * math.sin(math.radians(angle))

    print("{:.20f}".format(math.sqrt((x2 - x1)**2 + (y2 - y1) ** 2)))

if __name__ == '__main__':
    main()

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

rad_a = (360 / 12) * h + (360 / 12) * (m / 60)
rad_b = (360 / 60) * m
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(abs(rad_a-rad_b)))))

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

x = math.sqrt(pow(A,2) + pow(B,2) - 2*A*B*math.cos(abs((60*H+M)/2 - 6*M)*math.pi/180))

print(x)

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

Solution (Python):
import numpy as np
from scipy.spatial import distance

def rotation(x, t, deg = False):
    if deg == True:
        t = np.deg2rad(t)
    cos = np.cos(t)
    sin = np.sin(t)

    rot_x = [(x[0] * cos) - (x[1] * sin), (x[0] * sin) + (x[1] * cos)]
    
    return rot_x

if __name__ == "__main__":
    A, B, H, M = list(map(int, input().split()))
    
    a0 = np.array([0, A])
    b0 = np.array([0, B])

    a1 = rotation(a0, 0.5*(H*60+M), deg = True)
    b1 = rotation(b0, 6*M, deg = True)

    print(distance.euclidean(a1, b1))

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

import math

a = 30*H + 30*(M/60)
b =  6*M
sita = math.radians(abs(a-b))
cosh= math.cos(sita)
cc = A**2 + B**2 -2*A*B*cosh
c = cc**(1/2)
print(c)

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

import math

theta = min(abs(30*H-5.5*M),360-abs(30*H-5.5*M))
cos = math.cos(math.radians(theta))

d = math.sqrt(math.pow(A,2)+math.pow(B,2)-2*A*B*cos)

print(d)

Solution (Python):
import sys
import math
a,b,h,m = map(int, input().split())
h_rad=h*30+30*(m/60)
m_rad=m*6
if abs(h_rad-m_rad)>180:
    g=360-abs(h_rad-m_rad)
else:
    g=abs(h_rad-m_rad)


cosg=math.cos(math.radians(g))
C=a*a+b*b-2*a*b*cosg
c=math.sqrt(C)

print(c)

Solution (Python):
import math

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

wA = math.pi/6
wB = math.pi/30

thetaA = wA*(H+M/60)
thetaB = wB*M

dtheta = abs(thetaA-thetaB)
if dtheta > math.pi:
    dtheta = 2*math.pi - dtheta

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

print(c)

Solution (Python):

import math

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

    X_h = A*math.cos(math.radians(30*H + M/2))
    Y_h = A*math.sin(math.radians(30*H + M/2))
    X_m = B*math.cos(math.radians(6*M))
    Y_m = B*math.sin(math.radians(6*M))
    d = math.sqrt((X_h - X_m)**2 + (Y_h - Y_m)**2)
    print('{:.20f}'.format(d))


main()

Solution (Python):
import math
A,B,H,M = map(int,input().split())
H_pos = H/12 + M/720
M_pos = M/60
deg = 360*(H_pos-M_pos)
if deg > 180: deg = 360-deg
rad = math.radians(deg)
co = math.cos(rad)
print("{:.9f}".format(math.sqrt(A**2+B**2-2*A*B*co)))

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

H_angle = H*30 + M*0.5
M_angle = M*6

angle = abs(H_angle - M_angle)

if angle > 180:
    angle = 360 - angle

cos = math.cos(math.radians(angle))

C_pow = A**2 + B**2 - 2*A*B*cos


C = math.sqrt(C_pow)
C = float('{:.20f}'.format(C))
print(C)

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

tmp = M * 0.5
if H == 0:
    H = 12
if M == 0:
    M = 60

h = H*30
m = (M/5)*30

if h >= m:
    rad = (h+tmp)-(m)
else:
    rad = (m)-(h+tmp)

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

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

hour = h * (360/12) + m * 1/2
minute = m * (360/60)

ang = abs(minute - hour)
ang = 360 - ang

x = a*a + b*b -2*b*a * math.cos(math.radians(ang))
print(math.sqrt(x))

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


h_m = h * 60

h_dgree = (h_m + m)*0.5


m_dgree = m * 6


ab_dgree = h_dgree - m_dgree


result = a**2 + b**2 - 2*a*b*math.cos(math.radians(ab_dgree))
print(math.sqrt(result))

Solution (Python):
import math

L,S,H,M = map(int,input().split())


H = math.radians((H / 12)* 360 + M / 60 * 30)
M = math.radians(M / 60 * 360)


ax,ay = L * math.cos(H), L * math.sin(H)
bx,by = S * math.cos(M), S * math.sin(M)

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

Solution (Python):

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

hx = a*np.cos(-h*pi/6 + pi/2 - pi*m/360)
hy = a*np.sin(-h*pi/6 + pi/2 - pi*m/360)

mx = b*np.cos(-m*pi/30 + pi/2)
my = b*np.sin(-m*pi/30 + pi/2)

l = np.sqrt((hx-mx)**2+(hy-my)**2)

print(l)

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

from math import sin, cos, sqrt, pi

jishin_rad = ((h*60+m) / 720 * 360) * pi / 180
funshin_rad = (m / 60 * 360) * pi / 180

jishin = (sin(jishin_rad)*a, cos(-jishin_rad)*a)
funshin = (sin(funshin_rad)*b, cos(-funshin_rad)*b)

x_diff = jishin[0] - funshin[0]
y_diff = jishin[1] - funshin[1]
print(sqrt(x_diff**2 + y_diff**2))

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

jisin=h*30+m/2
hunsin=m*6

theta=math.radians(abs(jisin-hunsin))

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

Solution (Python):
import math
a,b,h,m=map(int,input().split())
 
dh=30*h+m/2
dm=6*m
 
if dm==dh:
    rad=0
else:
    rad=abs(dm-dh)
    
if rad>180:
    rad=360-rad
    length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(rad)))
 
elif 0<rad and rad<180:
    length=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(rad)))
 
elif rad==180:
    length=a+b
    
else:
    length=abs(a-b)
    
print(length)

Solution (Python):
import numpy as np


def get_rotation_matrix(rad):
    """
    指定したradの回転行列を返す
    """
    rot = np.array([[np.cos(rad), -np.sin(rad)],
                    [np.sin(rad), np.cos(rad)]])
    return rot


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

    radis_h = np.deg2rad((360 / 12) * h + 30*(m/60))
    radis_m = np.deg2rad((360 / 60) * m)

    a_point = np.array([0, 1])
    b_point = np.array([0, 1])

    rot_a = get_rotation_matrix(radis_h)
    rot_b = get_rotation_matrix(radis_m)

    a_fin = np.dot(rot_a, a_point) * a
    b_fin = np.dot(rot_b, b_point) * b
    return np.linalg.norm(a_fin - b_fin)


print(main())

Solution (Python):
import math
a,b,h,m = map(int,input().split())
num1 = m * 6
num2 = h * 30 + m * 0.5
if num1 >= num2:
  sita = num1 - num2
else:
  sita = num2 - num1
c2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(sita))
c = math.sqrt(c2)
print(c)

Solution (Python):
a,b,h,m=(int(x) for x in input().split())
import math
ka=360*(60*h+m)/720
kb=360*m/60
x=abs(ka-kb)
if x==360 or x==0:
    if a > b:
        print(a-b)
    else:
        print(b-a)
elif x==180:
    print(a+b)
elif x < 180:
    c=a**2+b**2-2*a*b*math.cos(math.radians(x))
    print(abs(math.sqrt(c)))
else:
    y=360-x
    c=a**2+b**2-2*a*b*math.cos(math.radians(y))
    print(abs(math.sqrt(c)))

Solution (Python):
import math

def main():
    a, b, H, M = map(int, input().split())

    
    

    
    M_angle = 6 * M
    H_angle = 0.5 * (H * 60 + M)
    angle = abs(M_angle - H_angle)
    
    print(math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(angle))))

if __name__ == "__main__":
    main()

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

import math  
import numpy

H = H + M / 60
H_A = H / 12 * 360 * math.pi /180
M_A = M / 60 * 360 * math.pi / 180
H_x = math.cos(H_A) * A  
H_y = math.sin(H_A) * A
M_x = math.cos(M_A) * B
M_y = math.sin(M_A) * B

a = numpy.array([H_x, H_y])
b = numpy.array([M_x, M_y])
u = b - a
print(numpy.linalg.norm(u))

Solution (Python):
import math

a, b, H, M = map(int, input().split())
a_ = 360 / 12
a2_ = 30 / 60
b_ = 360 / 60

print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(b_ * M - (a_* H + a2_ * M)))))

Solution (Python):
import math
def clock(h, m):
    res = abs((11*m)/2 - (30*h))
    if res>180: res = 360 - res
    return res
a,b, hour, min = map(int,input().split())

angle = clock(hour, min)
angle1 = math.cos(math.radians(angle))
ans = math.sqrt((a*a)+(b*b)-(2*a*b*angle1))
print("%.20f"%ans)

Solution (Python):
import math

def f(d, angle):
    r = math.radians(angle)
    x = d * math.cos(r)
    y = d * math.sin(r)
    return x, y

def main():
    A, B, H, M = map(int, input().split())
    x1, y1 = f(A, H / 12 * 360 + (M / 60 * 360 / 12))
    x2, y2 = f(B, M / 60 * 360)
    print(math.sqrt((x1-x2)**2 + (y1-y2)**2))

main()

Solution (Python):


import sys
import pprint
import math

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	a, b, h, m = map(int, sys.stdin.readline().split())
	log.print(a, b, h, m)
	mk = math.radians(360 - (360 / 60) * m)
	mx = math.cos(mk) * b
	my = math.sin(mk) * b
	hk = math.radians(360 - (360 / 12) * h - (360 / 12) * (m / 60))
	hx = math.cos(hk) * a
	hy = math.sin(hk) * a
	log.print(math.degrees(hk), math.degrees(mk), hx, hy, mx, my, )
	print(math.sqrt((hx-mx)**2+(hy-my)**2))


	


main()

Solution (Python):



import math

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

if(h>m):
    d=h-m
else:
    d=m-h
d*=6
c=a**2+b**2-2*a*b*math.cos(math.radians(d))
print('{:.23f}'.format(c**(1/2)))

Solution (Python):
import math
from decimal import Decimal

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

cos = math.cos(math.radians(Decimal(360.0*(H/12.0+M/(12*60)-M/60.0))))
C = Decimal(A**2 + B**2 - 2.0*A*B*cos)**Decimal('0.5')

print(C)

Solution (Python):
import math

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

a = int(a)
b = int(b)
h = int(h)
m = int(m)

kakudo_a = h * 30 + m * 0.5
kakudo_b = m * 6
kakudo = abs(kakudo_a - kakudo_b)

print('{:.20f}'.format(math.sqrt(a * a + b * b - (2 * a * b * math.cos(math.radians(kakudo))))))

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,h,m=LI()

  x=30*h+m/2
  y=360*(m/60)
  sita=abs(x-y)
  if sita>180:
    sita=360-sita

  z=a*a+b*b-(2*a*b*math.cos(sita*math.pi/180))
  return math.sqrt(z)


print(main())

Solution (Python):
import math
a,b,h,m = map(int,input().split())
def bbb(h,m):
    z = m/60
    x = ((h)*60 + m)/720
    z*=360
    x*=360
    c = min(abs(x-z),(360-abs(z-x)))


    
    

    ans = a**2 + b**2 - (2*a*b*math.cos(math.radians(c)))
    return ans**0.5
print(bbb(h,m))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
res = math.pi/2
hx = 0
hy = a
mx = 0
my = b
ho = res-2*math.pi*(h/12 + m/720)
mi = res-2*math.pi*m/60
hx = a*math.cos(ho)
hy = a*math.sin(ho)
mx = b*math.cos(mi)
my = b*math.sin(mi)

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

Solution (Python):

import math





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


h_angle = h * 30 + m * 0.5

m_angle = m * 6


angle = h_angle - m_angle

if angle >= 180:
    angle = m_angle + 360 - h_angle





c = (a * a + b * b - 2 * a * b * math.cos(math.radians(angle))) ** 0.5

print(c)

Solution (Python):
import math

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

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

long = M * 6
short = (H*60 + M) * 0.5
k = short - long
if k > 180:
    k = 360 - k
a = (A**2) + (B**2) - (2*A*B*math.cos(math.radians(k)))
print(a**(1/2))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
l_rad=6.0*M
s_rad=(60*H+M)/720*360
print(math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(abs(l_rad-s_rad)))))

Solution (Python):
import math
S=input()
S=S.split()
A=float(S[0])
B=float(S[1])
H=float(S[2])
M=float(S[3])
C=abs(30*H-5.5*M)
if C-180>0:
  C=360-C
C=C*(math.pi/180)
ans=math.sqrt(A*A+B*B-2*A*B*math.cos(C))
print(ans)

Solution (Python):
import math
import sys
import numpy as np
a,b,h,m=map(int,input().split())
h=h*30+m*0.5
m=m*6
ma=max(h,m)
mi=min(h,m)
kakudo=abs(ma-mi)
if kakudo>180:
    kakudo=360-kakudo
elif kakudo == 0:
    print(abs(a-b))
    exit()
elif kakudo==180:
    print(a+b)
    exit()

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

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

Solution (Python):
import math
A,B,H,M = list(map(int,input().split()))
h = 360 / 720 * M + 30 * H
m = 360 / 60 * M

Cs1 = math.fabs(h - m)
Cs2 = math.fabs(360 - Cs1)
Csl = [Cs1,Cs2]
Cs = min(Csl)

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

Solution (Python):
import numpy as np
a,b,h,m = map(int, input().split())
H = 30*h + 0.5*m
M = 6*m
k = H-M
if k>=180:
    k = (360- k)*(np.pi/180)
else:
    k = k*(np.pi/180)
c = a**2 + b**2 - 2*a*b*np.cos(k)
print(np.sqrt(c))

Solution (Python):
import math

import numpy as np
from scipy.spatial import distance

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


radian_hour_hand = math.radians(360 * (H + M / 60) / 12)

radian_minute_hand = math.radians(360 * M / 60)

radian_diff = radian_hour_hand - radian_minute_hand

x_hour_hand = A * math.cos(radian_hour_hand)
y_hour_hand = A * math.sin(radian_hour_hand)


vector_hour_hand = np.array([x_hour_hand, y_hour_hand])
coord_hour_hand = (x_hour_hand, y_hour_hand)


x_minute_hand = B * math.cos(radian_minute_hand)
y_minute_hand = B * math.sin(radian_minute_hand)


vector_minute_hand = np.array([x_minute_hand, y_minute_hand])
coord_minute_hand = (x_minute_hand, y_minute_hand)


vector_diff = vector_hour_hand - vector_minute_hand
distance = distance.euclidean(coord_hour_hand, coord_minute_hand)



print(distance)

Solution (Python):
import math


def calc_minutes(h, m):
    return 60 * h + m


def to_angle_minutes(h, m):
    minutes = calc_minutes(h, m)

    minutes_角度 = minutes / 60

    shousu = math.modf(minutes_角度)[0]

    angle_minutes = 360 * shousu

    return angle_minutes


def to_angle_hours(h, m):
    minutes = calc_minutes(h, m)

    hours_角度 = minutes / 720

    shousu = math.modf(hours_角度)[0]

    angle_hours = 360 * shousu

    return angle_hours


def to_cosC(angle_hours, angle_minutes):
    C = abs(angle_hours - angle_minutes)
    C_rad = math.radians(C)
    cosC = math.cos(C_rad)

    return cosC


def actual(a, b, h, m):
    angle_hours = to_angle_hours(h, m)
    angle_minutes = to_angle_minutes(h, m)

    cosC = to_cosC(angle_hours, angle_minutes)

    c = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cosC)

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

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

Solution (Python):
import math

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

degH = 30 * H + 0.5 * M
degM = 6 * M

digA = abs(degH - degM) * math.pi / 180

if digA <= math.pi /2 :
    ans = float(math.sqrt((A**2) + (B**2) - (2*A*B*math.cos(digA))))
else:
    ans = float(math.sqrt((A**2) + (B**2) - (2*A*B*math.cos(-digA))))

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

Solution (Python):
import math

a,b,h,m = map(float,input().split())
if 6*m>30*h+m*0.5:
  angle = (6*m) - (30*h+m*0.5)
else:
  angle = (30*h+m*0.5) - (6*m)

if angle>180:
  angle = 360-angle

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

Solution (Python):
import math

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

x = ((M * 1/2) + (H * 30)) - (M * 6)

R = math.radians(x)
COS = math.cos(R)
re = (A**2) + (B**2) - 2 * (A * B) * COS

print(re**0.5)

Solution (Python):
import numpy as np
a,b,h,m = map(int, input().split())
short_arg = (h*60+m) * 0.5  
long_arg = m * 6 
theta = np.abs(short_arg - long_arg)
c = np.sqrt(a**2 + b**2 - 2*a*b*np.cos(theta * np.pi/180))
print(c)

Solution (Python):
import math
II=input().split()
A = int(II[0])
B = int(II[1])
H = int(II[2])
M = int(II[3])
a=H/12*360 + M/60/12*360
b = M/60*360



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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline

import math


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

theta_a = 360 * h / 12 + m / 2
theta_b = 360 * m / 60

if ((theta_a <= 180) & (theta_b <= 180)) or \
    ((theta_a >= 180) & (theta_b >= 180)):
    theta_a = min(theta_a, 360 - theta_a)
    theta_b = min(theta_b, 360 - theta_b)
    theta = abs(theta_b - theta_a) * math.pi / 180
else:
    theta_a = min(theta_a, 360 - theta_a)
    theta_b = min(theta_b, 360 - theta_b)
    theta = abs(theta_b + theta_a) * math.pi / 180

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

print(c ** 0.5)

Solution (Python):
import math
it = input()
it = it.split()
a = int(it[0])
b = int(it[1])
h = int(it[2])
m = int(it[3])

k = h * 30 + m * 0.5
s = m * 6
if s == 0:
    s = 360
if k == 0:
    k = 360

if k < s:
    u = s-k
else:
    u = k-s
u = u / 180.0 * math.pi 
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(u))

print(c)

Solution (Python):
import sys 
import math
a = list(map(int,input().split()))
A = a[0]
B = a[1]
H = a[2]
M = a[3]

short_needle_angle = (360*(M/60))
if H >= 12:
    H = H -12
long_needle_angle = (360*(H/12)) + (30*(M/60))
angle = abs(long_needle_angle - short_needle_angle)

if angle > 180:
    angle = 360 - angle
red = math.radians(angle)
a = (A ** 2) + (B ** 2) - (2* A *B * math.cos(red))
print(math.sqrt(a))

Solution (Python):
import math

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

tan = H * 30 + M * 0.5
tyo = M * 6
C2 = 0

kaku = abs(tan - tyo)

if kaku > 180 :
    kaku = 360 - kaku 

if kaku == 180 :
    print(A + B)

elif kaku == 0 :
    print(abs(B - A))

else:
    C2 = A**2 + B**2 - 2*A*B*math.cos(math.radians(kaku))
    print(math.sqrt(C2))

Solution (Python):
import math


def cal():
    string = input()
    a, b, h, m = string.split(" ")
    a = int(a)
    b = int(b)
    h = int(h)
    m = int(m)
    minuteAngel = (float(m) * 360) / 60
    hourAngel = (float(h) % 12) * 30 + (float(m) * 30) / 60
    angel = abs(hourAngel - minuteAngel)
    angel=angel/180
    cosine = math.cos(math.pi*angel)
    ans = math.sqrt(a*a + b*b - 2*a*b*cosine)
    print(format(ans, '.20f'))
    
    
    
    

cal()

Solution (Python):
import math

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

Acos = float('{:.10f}'.format(A * math.cos(math.radians((30*H) + (0.5*M)))))
Bcos = float('{:.10f}'.format(B * math.cos(math.radians(6*M))))
Asin = float('{:.10f}'.format(A * math.sin(math.radians((30*H) + (0.5*M)))))
Bsin = float('{:.10f}'.format(B * math.sin(math.radians(6*M))))

cos = (Acos - Bcos) ** 2
sin = (Asin - Bsin) ** 2
print(math.sqrt((cos + sin)))

Solution (Python):
import math as mt
a, b, h, m = list(map(int, input().split()))
h_e = 360/12
m_e = 360/60


ang = abs(h_e*(h + m/60) - m*m_e)
if ang > 180:
  ang = 180 - (ang%180)
print('{:.12f}'.format(mt.sqrt(a*a + b*b -2*a*b*mt.cos(ang/360*2*mt.pi))))

Solution (Python):
import math
p = math.pi
A,B,H,M = map(int,input().split())
thita1 = 2*p*H/12+2*p/12*M/60
thita2 = 2*p*M/60
sin1 = math.sin(thita1)
sin2 = math.sin(thita2)
cos1 = math.cos(thita1)
cos2 = math.cos(thita2)
l2 = (A*sin1-B*sin2)**2+(A*cos1-B*cos2)**2
l = math.sqrt(l2)
print(l)

Solution (Python):
import math

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

th_max = 12 * 60
tm_max = 60
th = H * 60 + M
tm = M
degA = 2 * math.pi * tm / tm_max
degB = 2 * math.pi * th / th_max
deg = abs(degA-degB)

cos_deg = math.cos(deg)

res = (A**2 + B**2 - 2*A*B*cos_deg)**(0.5)
print(res)

Solution (Python):
import math

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

rad_M = math.radians(6*M)
rad_H = math.radians(30*H+0.5*M)
rad = abs(rad_M-rad_H)
if rad >= math.pi:
  rad = 2*math.pi - rad

S = (A**2) + (B**2) - 2*A*B*math.cos(rad)
S = S**0.5
print(S)

Solution (Python):
import math

a,b,h,m = [int(i) for i in input().split()]
a_rad = 0.5 * (60*h+m)
b_rad = 6*m

rad_diff = abs(a_rad - b_rad)

x2 = a*a + b*b -2*a*b*math.cos(math.radians(rad_diff))

print(math.sqrt(x2))

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

Solution (Python):
from math import *

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

angle_H = (60*H + M) * 2 * pi / 720
angle_M = M * pi / 30

angle = pi + abs(pi - abs(angle_H - angle_M))

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

print(ans)

Solution (Python):
import math

A, B, H, M = map(int, input().split())
tan = 30 * H + (30 * (M / 60))
tyo = 6 * M
kakudo = abs(tan - tyo)

ans = pow(A, 2) + pow(B, 2) - 2 * A * B * math.cos(math.radians(kakudo))
print(pow(ans, 0.5))

Solution (Python):
import math

Line = [int(s) for s in input().split()]

A,B,H,M = Line[0],Line[1],Line[2],Line[3]



kakudo = abs(  H/12*360 + M/12/60*360 - M/60*360 )

if kakudo > 180 :
    kakudo = 360 - kakudo



ans = math.sqrt(A**2 + B**2 - 2*A*B*round(math.cos(math.radians(kakudo)),100))

print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
P=H*30-M*5.5
c = math.cos(math.radians(P))
L=A*A+B*B-2*A*B*c
x=math.sqrt(L)
print(x)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
c = h * 30 + m * 0.5
d = m * 6
x = min(abs(c-d), 360-abs(c-d))
if x <= 180:
    e = x
else:
    e = x-180
f = e/180*math.pi
if e == 0:
    print(abs(a-b))
elif e == 180:
    print(a+b)
else:
    print(math.sqrt(a*a + b*b - (2*a*b*math.cos(f))))

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

Solution (Python):
import math
a,b,h,m = map(int,input().split())
x = 30*h + 0.5*m
y = 6*m
if x > y:
  s = x-y
else:
  s = y-x
t = math.cos(math.radians(s))
c = ((a**2) + (b**2) - 2 * a * b * t) ** 0.5
print(c)

Solution (Python):
import math

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


if M == 0 and H == 6:

    print(A+B)

elif M == 0 and H == 0:

    print(abs(A-B))

else:
    angulo = abs(11 * M - 60 * H)/2

    angulo = math.radians(angulo)

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

Solution (Python):
import math
A,B,H,M = map(int,input().split())
angle = (H* 30 + M *0.5) - (M * 6)
R = math.radians(angle)
output = (A**2) +(B**2) - (2*A*B*math.cos(R))
print(output**0.5)

Solution (Python):

import math

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

time = h + m/60

anglea = (time/12)*360 % 360

a_x = a*math.sin(math.radians(anglea))
a_y = a*math.cos(math.radians(anglea))

angleb = time*360 % 360

b_x = b*math.sin(math.radians(angleb))
b_y = b*math.cos(math.radians(angleb))


result = math.sqrt((a_x-b_x)**2 + (a_y-b_y)**2)
print('{:.12f}'.format(result))

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

dA=(60*H+M)/2
dB=6*M
rad=dA-dB

C=math.radians(rad)

c=(A**2+B**2-2*A*B*math.cos(C))**0.5
print(format(c,'.10f'))

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

Solution (Python):
import math

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


minutes_x = math.sin(math.radians(minutes * 6)) * short
minutes_y = math.cos(math.radians(minutes * 6)) * short

diff = 360 / 12 * minutes / 60

hour_x = math.sin(math.radians(hour * 30 + diff)) * long
hour_y = math.cos(math.radians(hour * 30 + diff)) * long


print(math.sqrt((hour_x - minutes_x) ** 2 + (hour_y - minutes_y) ** 2))

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

from math import *


def linput(_t=int):
    return list(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():

    A,B,H,M = linput()
    
    

    ta = M / 60 * 2 * pi
    tb = (H * 60 + M) / (12 * 60) * 2 * pi

    xa = A * sin(ta)
    ya = A * cos(ta)

    xb = B * sin(tb)
    yb = B * cos(tb)

    res = sqrt((xa-xb)**2 + (ya-yb)**2)

    print("{:.14f}" .format(res))
    
    


main()

Solution (Python):
import math
def solve():
    A,B,H,M = map(int,input().split())
    minute = H * 60 + M
    hour_angle = 360 * 1/720 * minute
    minute_angle = 360 * 1/60 * M

    angle = 0
    if hour_angle > minute_angle:
        angle = hour_angle - minute_angle
    else:
        angle = minute_angle - hour_angle
    
    print(geta(A,B,min(angle,360-angle)))

def geta(b,c,A):
    a2 = b**2 + c**2 - (2*b*c*math.cos(math.radians(A)))
    return math.sqrt(a2)
if __name__ == '__main__':
    solve()

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

dA = (H*60+M)*math.pi/360
dB = M*math.pi/30
dC = abs(dB - dA)
C = (A**2 + B**2 - 2*A*B*math.cos(dC))**(1/2)

print(C)

Solution (Python):
import math

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

theta = math.radians(360 * (H / 12 + M / (12 * 60) - M / 60))

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

Solution (Python):
import math
A,B,H,M=map(int,input().split())
s=(60*H+M)*60
t=(1/120)*s 
u=6*M 
v=abs(t-u)
if 0<v<=180:
  k=math.cos(math.radians(v))
  C=math.sqrt(A**2+B**2-2*A*B*k)
  print(C)
elif v>=180:
  w=360-v
  k=math.cos(math.radians(w))
  C=math.sqrt(A**2+B**2-2*A*B*k)
  print(C)    
elif v==0:
  print(abs(B-A))

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

import math
import numpy as np 

rad_1 =( (h/6) * math.pi ) + ( (m/360) * math.pi )

rad_2 = m/30 * math.pi 

angle_1 = a * np.array([np.cos(rad_1),np.sin(rad_1)])

angle_2 = b * np.array([np.cos(rad_2),np.sin(rad_2)])






inner = np.inner(angle_1,angle_2)

cos_theta = inner/(a*b)




ans = (a**2) + (b**2) - 2 * a * b * cos_theta

print(np.sqrt(ans))

Solution (Python):
import math
import numpy as np
op = list(map(int,input().split()))
a = op[0]
b = op[1]
h = op[2]
m = op[3]
hs = h*30
d = abs(hs-5.5*m)
d = np.radians(d)
cd = np.cos(d)
x = math.sqrt(a**2+b**2-2*a*b*cd)
print(x)

Solution (Python):
import math

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

omega_A = 6
omega_B = 30

degree_A = omega_A * M
degree_B = omega_B * H + ((omega_B / 60) * M)
degree_AB = abs(degree_A - degree_B)

if degree_AB > 180:
  degree_AB = 360 - degree_AB
  
C = (A**2 + B**2 - 2*A*B*math.cos(math.radians(degree_AB)))**0.5  

print(C)

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

Solution (Python):
import math

a, b, h, m = map(int, input().split())
x = a*(math.cos(math.radians(30*h+0.5*m)))-b*(math.cos(math.radians(6*m)))
y = a*(math.sin(math.radians(30*h+0.5*m)))-b*(math.sin(math.radians(6*m)))
ans = math.sqrt(x**2+y**2)
print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
zi=(h*60+m)/720*2*math.pi
hun=m/60*2*math.pi
xzi=a*math.sin(zi)
yzi=a*math.cos(zi)
xhun=b*math.sin(hun)
yhun=b*math.cos(hun)
p=(xzi-xhun)**2+(yzi-yhun)**2
print('{:.18f}'.format(math.sqrt(p)))

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

"""
h = (H / 12 + (M / 60 / 12)) * 2 * math.pi
m = M / 60 * 2 * math.pi

ax = A * math.cos(h)
ay = A * math.sin(h)

bx = B * math.cos(m)
by = B * math.sin(m)



ans = ((ax-bx)**2 + (ay-by)**2 )**(1/2)

print(ans)
"""

ang = ((H / 12 + (M / 60 / 12)) - (M / 60)) * 360



C = ang * math.pi / 180 if ang < 180 else (360 - ang) * math.pi / 180



c2 = A**2 + B**2 - 2 * A * B * math.cos(C)

print((c2)**(1/2))

Solution (Python):
import math
a,b,h,m = [int(i) for i in input().split()]
s = min(abs(h * 30 + m * 0.5 - m * 6), 360 - abs(h * 30 + m * 0.5 - m * 6))
print(math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(s))))

Solution (Python):
import math

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

aa=a*a
bb=b*b


mm=m*6

hh=h*30+30*m/60
if hh-mm<=180:
    cos = math.cos(math.radians(abs(hh-mm)))
else:
    cos = math.cos(math.radians(360-abs(hh-mm)))

cc=aa+bb-2*a*b*cos

c=math.sqrt(cc)

print(c)

Solution (Python):
import math

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

sita1=M*360/60
sita2=H*360/12+0.5*M

a=abs(sita1-sita2)
if a > 180:
    a = 360 - a
d = math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(a)))

print('{:.20f}'.format(d))

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

H_Angle = (H * 60 + M) * 0.5
M_Angle = M * 6
difAngle = M_Angle - H_Angle
ans_2 = A**2 + B**2 - 2 * A * B * math.cos(math.radians(difAngle))

print(math.sqrt(ans_2))

Solution (Python):
import math

inputLine = input()
tempStr = inputLine.split(' ')

a = int(tempStr[0])
b = int(tempStr[1])
h = int(tempStr[2])
m = int(tempStr[3])

minDeg = 360 * (m / 60)
hourDeg = h * 30 + (30 * (m / 60))

finalValue = hourDeg - minDeg if hourDeg >= minDeg else minDeg - hourDeg
finalValue = 360 - finalValue if finalValue >= 180 else finalValue

if finalValue == 90 :
	print(math.sqrt((a * a) + (b * b)))
elif finalValue == 0 or finalValue == 180 :
	if b >= a :
		print(b - a if finalValue == 0 else b + a)
	else :
		print(a - b if finalValue == 0 else a + b)
else :
	print(math.sqrt((a * a) + (b * b) - (2 * a * b * math.cos(math.pi * (finalValue / 180)))))

Solution (Python):
import math
A,B,H,M=map(int,input().split())
print('{:.20}'.format(math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(30*H-(11*M)/2)))))

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

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