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

Hw = H / 12 * 360 + M * 0.5
Mw = M / 60 * 360


A1, A2 = A * math.cos(math.radians(Hw)), A * math.sin(math.radians(Hw))
B1, B2 = B * math.cos(math.radians(Mw)), B * math.sin(math.radians(Mw))

print(math.sqrt((A1 - B1) ** 2 + (A2 - B2) ** 2))

Solution (Python):
import math

if __name__ == "__main__":
    num = list(map(int, input().split()))

    a = num[0]
    b = num[1]
    h = num[2]
    m = num[3]

    deg = abs(30 * h + 0.5 * m - 6 * m)
    
    rad = math.radians(deg)
    
    c_2 = a * a + b * b - 2 * a * b * math.cos(rad)
    c = math.sqrt(c_2)

    print(c)

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

def calcAngle(h,m): 
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            return 0 
          
        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())

l=calcAngle(h,m)*pi/180

w=pow(a,2)+pow(b,2)-2*a*b*cos(l)
print(sqrt(w))

Solution (Python):
import math


def convert_min(h, m):
    t_min = h * 60 + m
    return t_min


def main():
    a, b, h, m = [int(v) for v in input().split(' ')]

    t_min = convert_min(h, m)

    angle_a = ((t_min * 0.5) % 360)
    angle_b = ((t_min * 6) % 360)

    diff_angle = abs(angle_a - angle_b)
    diff_angle = min(360 - diff_angle, diff_angle)
    d = diff_angle / 180 * math.pi

    l2 = (b * math.cos(math.pi / 2 - d)) ** 2 + \
        (a - b * math.sin(math.pi / 2 - d)) ** 2
    l = math.sqrt(l2)
    print(l)


if __name__ == '__main__':
    main()

Solution (Python):
import math

def resolve():
    a,b,h,m = map(int, input().split())
    a_deg = h*30 + m*0.5
    b_deg = m*6
    angle = abs(a_deg - b_deg)
    if angle == 0 or angle == 360:
        print(abs(b-a))
        return
    elif angle == 180:
        print(a+b)
        return 
    elif angle > 180:
        angle = 360 - angle
    rad = math.radians(angle)
    sq_c = a*a + b*b - 2*a*b*math.cos(rad)
    print(math.sqrt(sq_c))

resolve()

Solution (Python):
import math

def main():
  a, b, h, m = map(int, input().split())
  m_rad = m / 60 * 360
  h_rad = h / 12 * 360 + (m / 60) * (360 // 12)
  s = 0
  if h_rad > m_rad:
    s = min(h_rad - m_rad, 360 - h_rad + m_rad)
  else:
    s = min(m_rad - h_rad, 360 - m_rad + h_rad)

  s = math.radians(s)

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


main()

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




Mr=M*2*pi/60
Hr=(H+M/60)*2*pi/12

R=0
R=Mr - Hr


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

Solution (Python):
A,B,H,M=input().split()
a=int(A)
b=int(B)
h=int(H)
m=int(M)
import math
p=math.pi
x=(2*p*h/12)+(p*m/360)-(2*p*m/60)
y=2*p-x
z=min(x,y)
c=math.cos(z)
l2=a*a+b*b-2*a*b*c
l=math.sqrt(l2)
print(l)

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

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

if H == 6 and M == 0:
    print(A+B)
    exit()


kaku = abs((6*M-(0.5*M+H*30)))
if kaku > 180:
    kaku = 360 - kaku





print(sqrt(A**2 + B**2 -2*A*B*cos(radians(kaku))))

Solution (Python):
import sys
from math import sin, cos, pi, sqrt
S = sys.stdin.read()
A, B, H, M = [int(x) for x in S.split()]

angle_a = 2 * pi / 60 * M
angle_b = 2 * pi * (H / 12 + M / 60 / 12)
ax = sin(angle_a) * A
ay = cos(angle_a) * A
bx = sin(angle_b) * B
by = cos(angle_b) * B
d = sqrt((ax - bx) ** 2 + (ay - by) ** 2)
print(d)

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

h_angle=30*h+0.5*m
m_angle=6*m
sa_angle=abs(h_angle - m_angle) 


if(sa_angle > 180 ):
    sa_angle=360- sa_angle

theta=(sa_angle / 180) * math.pi
c_2=a*a +b*b -2*a*b*math.cos(theta)
c=math.sqrt(c_2)
print(c)

Solution (Python):

MOD=10**9+7
INT_MAX=10**18+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
def power(a,x):
    res=1
    while(x>0):
        if x&1:
            res=(res*a)%MOD
        a=(a*a)%MOD
        x//=2
    return res%MOD
def NCR_MOD(n,r):
    num=1
    for i in range(n,n-r,-1):num=(num*i)%MOD
    for j in range(1,r+1):num=(num*power(j,MOD-2))%MOD
    return num

import math as M
a,b,h,m=INPUT()
thetha=abs(30*h-6*m+0.5*m)
if thetha>180:
    thetha=360-thetha


c=M.sqrt(b**2+a**2-2*a*b*M.cos(thetha*M.pi/180))
print(c)

Solution (Python):
import math
a = list(map(int,input().split()))
b = a[2] * 30 + a[3]/2
c = a[3]*6
d = math.sqrt(a[0]**2 + a[1]**2 - 2*a[0]*a[1]*math.cos(math.radians((abs(b-c)))))
print(d)

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

theta = H * 30 * math.pi/180 + M * math.pi/360
phi = M * 6 * math.pi/180

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

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

buf = abs(phi-theta)
c = A ** 2 + B ** 2 - 2 * A * B * math.cos(buf)
print(math.sqrt(c))

Solution (Python):
import numpy as np
import math

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


t = 60 * h + m

sa = ( 2.0e0 * np.pi ) / ( 12 * 60 )
sb = ( 2.0e0 * np.pi ) / 60


arad = sa * t
brad = sb * t
delab = brad - arad
prod  = int( delab / ( 2.0e0 * np.pi ) )
delab = delab - 2.0e0 * np.pi * prod



l2 = a*a + b*b - 2.0e0*a*b*np.cos( delab )
l  = np.sqrt( l2 )
print( l )

Solution (Python):

"""
Created on Sun May 17 21:16:04 2020

@author: Kei
"""

import math

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


theta_s = H*30 + M*0.5
theta_l = M*6


theta = abs(theta_s-theta_l)

if theta > 180:
    theta = 360 - theta


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

print(C)

Solution (Python):
import math
a, b, hour, mini = map(int, input().split())
if (hour == 12): 
    hour = 0
if (mini == 60): 
    mini = 0
h = 0.5 * (hour * 60 + mini) 
m = 6 * mini 
angle = abs(h - m)
angle = min(360 - angle, angle)
angle = (angle * (math.pi) / 180)

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

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

tan_kakudo = (360 / 12 * H) + (360 / 12 / 60 * M) 
tyo_kakudo = (360 / 60 * M)
diff_kakudo = abs(tan_kakudo - tyo_kakudo)
if diff_kakudo >= 180:
    diff_kakudo = 360 - diff_kakudo
ans = math.sqrt((A ** 2) + (B ** 2) - (2 * A * B * math.cos(math.radians(diff_kakudo))))
print(ans)

Solution (Python):
import math

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

hour_r = (0.5*H*60) + M*0.5

minu_r = 6*M

if hour_r > minu_r:
    k = hour_r - minu_r
else:
    k = minu_r - hour_r
k = min (k,360-k)


ans_2 = (A**2+B**2)-2*A*B*(math.cos(math.radians(k)))
print(ans_2**0.5)

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

x_1 = a * math.cos(((90-30*h-0.5*m)/180)*math.pi)
y_1 = a * math.sin(((90-30*h-0.5*m)/180)*math.pi)
x_2 = b * math.cos(((90-6*m)/180)*math.pi)
y_2 = b * math.sin(((90-6*m)/180)*math.pi)


print(math.sqrt((x_1-x_2)**2 + (y_1-y_2)**2))

Solution (Python):

import math

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

tankakudo = 30 * h + 0.5 * m


chokakudo = 6 * m


if tankakudo > chokakudo:
    naskakudo = tankakudo - chokakudo
else:
    naskakudo = chokakudo - tankakudo
    
if naskakudo > 180:
    naskakudo = 360 - naskakudo

Answer = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(naskakudo)))
print("{:.20f}".format(Answer))

Solution (Python):

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

def yo(a, b, c):
    
    
    tmp = pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(c)
    return pow(tmp, 0.5)
ss = (h / 12 + m / 720) * 2 * math.pi
ls = m / 60 * 2 * math.pi

ans = yo(a, b, min(abs(ls - ss), 2*math.pi - abs(ls - ss)))
print(ans)

Solution (Python):

from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce


MOD = 1000000007

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def main():
    A,B,H,M = [int(x) for x in stdin.readline().rstrip().split()]
    m_deg = M * 6
    h_deg_kari = (H * 30) + (M * 0.5)
    h_deg = min(abs(h_deg_kari - m_deg), 360 - abs(h_deg_kari - m_deg))
    
    if h_deg == 0:
        print(abs(A-B))
    elif h_deg == 180:
        print(A+B)
    else:
        print(math.sqrt(A ** 2 + B ** 2 - (2 * A * B * math.cos(math.radians(h_deg)))))
    
main()

Solution (Python):
import math

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


a_theta = math.radians(30 * (h%12) + m/2)
b_theta = math.radians(6 * m)

if(a_theta >= b_theta and b_theta != 0):
    theta = a_theta - b_theta
else:
    theta = b_theta - a_theta

def yogen(a, b, theta):

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

print(yogen(a, b, theta) ** 0.5)

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


mi = H * 60 + M

b = Decimal(360 * M) / Decimal(60)
a = Decimal(360 * mi) / Decimal(720)

t = math.radians(max(a, b) - min(a, b))
t = math.cos(t)
print(math.sqrt(Decimal(A**2)+Decimal(B**2)-Decimal(2*A*B*t)))

Solution (Python):
import math

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

def c_side(a, b, c):
    ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(c))
    return ans

a, b, h, m = [int(i) for i in input().split()]
c_angle = third_angle(h, m)
c_angle = math.radians(c_angle)
ans = c_side(a, b, c_angle)
print(ans)

Solution (Python):
import math 
hour , minute , h , m = map(int,input().split())
ht = h + m/60 
h_angle = (2*math.pi/12)*ht 
m_angle = (2*math.pi/60)*m 
angle = abs(h_angle-m_angle)
angle = min(2*math.pi-angle,angle)
ans = (hour**2 + minute**2 - 2*hour*minute*(math.cos(angle)))
print(ans**0.5)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
 
h = H*30 + M/2
m = 6*M
K = abs(h - m)
if K > 180:
  K = 360 - K
c = math.cos(math.radians(K))

aa = A**2 + B**2 -2*A*B*c

print(math.sqrt(aa))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
p1 = 30 * h + m / 2
p2 = 6 * m
s = min(abs(p1 - p2), abs(abs(p1 - p2) - 360))
ans = pow(a * math.sin(math.radians(s)), 2) + pow((b - a * math.cos(math.radians(s))), 2)
print((ans) ** (1 / 2))

Solution (Python):

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

H_deg = 30 * H + 0.5 * M
M_deg = 6 * M

HM_rad = math.radians(min(abs(H_deg - M_deg), 360 - abs(H_deg - M_deg)))
print(math.sqrt((A ** 2) + (B ** 2) - 2 * A * B * math.cos(HM_rad)))

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

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

tan = np.array([0, A])
chou = np.array([0, B])

tanrot = get_rotation_matrix(((-30*H-0.5*M)*np.pi)/180) 
chourot = get_rotation_matrix(((-6*M)*np.pi)/180)

tan = np.dot(tanrot, tan)
chou = np.dot(chourot, chou)
zero = np.array([0, 0])

print(np.linalg.norm(chou-tan))

Solution (Python):
import math
a, b, h, m = map(float, input().split())
mm = (m % 60.0) * 6.0
hh = h * 30.0 + m * 0.5

rad = (mm - hh) * math.pi / 180.0
c = math.sqrt(math.pow(a, 2) + math.pow(b, 2) - 2 * a * b * math.cos(rad))

print(c)

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

import math
x, y = min(A, B), max(A, B)

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

x = A*math.cos(math.radians(h))
y = A*math.sin(math.radians(h))
X = B*math.cos(math.radians(m))
Y = B*math.sin(math.radians(m))

ans = ((X-x)**2 + (Y-y)**2)**(1/2)

print(ans)

Solution (Python):
import math

A,B,H,M = map(int, input().split())
H_angle = H*30 + 0.5*M 
M_angle = M*6
angle = abs(H_angle-M_angle)
dis =math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(angle)))
print(dis)

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

needle= math.fabs(5.5 * M - 30 * H)
C = pow(A**2 + B**2 - 2*A*B*math.cos(math.radians(needle)),0.5)

print(C)

Solution (Python):
import math

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


Asin = a*math.sin(math.radians(h*360/12+m*30/60))
Acos = a*math.cos(math.radians(h*360/12+m*30/60))
Bsin = b*math.sin(math.radians(m*360/60))
Bcos = b*math.cos(math.radians(m*360/60))



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

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

Solution (Python):
import math

li = list(map(int,input().split()))
A=li[0]
B=li[1]
H=li[2]
M=li[3]

long = M/60 * 360
short = H/12 * 360 + M/60 * 30

def f(a,b,angle):
    c2 = a*a + b*b -2*a*b*math.cos(math.radians(angle))
    return math.sqrt(c2)

angle = 0
ans = 0
if(short==long):
    ans = abs(A-B)
elif(abs(short-long) == 180):
    ans = A+B
else:
    angle = abs(short-long)
    if(angle > 180):
        angle = 360 - angle
    ans = f(A,B,angle)

print(ans)

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi, cos
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


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

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    A, B, H, M = mulinputs()
    if H == 0 and  M == 0:
            print(abs(A-B))
            exit()

    l = 1/(60*12)
    s = 1/60
    H = l * (H*60+M)
    M = s * M
    H *= 360
    M *= 360
    alpha = abs(H-M)
    alpha *=pi/180

    
    print(sqrt(A*A+B*B-2*A*B*cos(alpha)))

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


h_k = h * 360/12 + m * 1/2
m_k = m * 360/60

if m == 0:
    m_k = 360

 

kakudo = abs(h_k - m_k)

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

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


long = M*6
short = (H*60+M)*360/(12*60)
s = short - long
import math
cos = math.cos(math.radians(s))
l = math.sqrt(A**2 + B**2 - 2*A*B*cos)
print(l)

Solution (Python):
import math
t = input().split()
t = [int(i) for i in t]
r = math.sqrt(t[0]*t[0]+ t[1]*t[1])
h = t[2]
m = t[3]
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)
print(math.sqrt(r*r - 2*t[0]*t[1]*math.cos(angle*(2*math.pi/360))))

Solution (Python):
import math
a, b, h, m = map(int,input().split())
 
ha = 360/12*h+0.5*m
ma = 360/60*m
 
s =  abs(ha-ma)
if s >180:
  s=360-s
 
ans = (a**2 + b**2 -2*a*b*math.cos(math.radians(s)))**(1/2)
 
print(ans)

Solution (Python):
import math

def main():
  A, B, H, M = map(int, input().split())
  Ax = A * math.sin((H + M / 60) * 30 / 180 * math.pi)
  Ay = A * math.cos((H + M / 60) * 30 / 180 * math.pi)
  Bx = B * math.sin(M * 6 / 180 * math.pi)
  By = B * math.cos(M * 6 / 180 * math.pi)
  dist = math.sqrt((Ax - Bx) ** 2 + (Ay - By) ** 2)
  print(dist)

if __name__ == '__main__':
  main()

Solution (Python):
import math
a, b, h, m = map(int, input().split())
degm = m*6
degh = h*30+degm/360*30
diff = abs(degh-degm)
rad = diff/180 * math.pi
c = math.sqrt(a**2+b**2-2*a*b*math.cos(rad))
print(c)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
hkaku = 30*h+30*m/60
mkaku = m*6
aidakaku = abs(hkaku-mkaku)
if aidakaku >180:
    aidakaku = 360-aidakaku
kaku = aidakaku*2*math.pi/360
answer = math.sqrt((a**2+b**2-2*a*b*math.cos((math.radians(aidakaku)))))
print(answer)

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

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

Solution (Python):

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

theta_a = math.pi * float(h + m / 60) / float(6)
theta_b = math.pi * float(m) / float(30)

theta = theta_a - theta_b
if theta > math.pi or theta < 0:
    theta = theta_b - theta_a

square_l = - float(2) * math.cos(theta) * float(a*b) + a * a + b * b
print(math.sqrt(square_l))

Solution (Python):
import math

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

al=math.radians((h*60+m)/2)
be=math.radians(m*6)

length=math.sqrt(pow(a*math.cos(al)-b*math.cos(be),2)+pow(a*math.sin(al)-b*math.sin(be),2))

print(length)

Solution (Python):
from math import pi, sin, cos, tan, sqrt, radians
a, b, h, m = map(int, input().split())

angle_a = -2 * pi * (h / 12) + (-2*pi*(1/12) * (m/60)) + radians(90)
angle_b = -2 * pi * (m / 60) + radians(90)

ax, ay = a * cos(angle_a), a * sin(angle_a)
bx, by = b * cos(angle_b), b * sin(angle_b)
print(sqrt(pow(ax-bx, 2)+pow(ay-by, 2)))

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






time = H*60 +M

cho = 6*M
tan = 0.5*time

if cho > tan:
    kakudo = cho - tan
else:
    kakudo = tan - cho

if kakudo > 180:
    kakudo = 360 - kakudo

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

print(ans)

Solution (Python):
import math
def main():
    a, b, h, m = map(float, input().split())
    rshort = 30*h + m*1/2
    rlong = 6*m
    ang = abs(rlong-rshort)
    ans = a**2 + b**2 -2*a*b*math.cos(math.radians(ang))
    return print(math.sqrt(ans))

if __name__ == '__main__':
    main()

Solution (Python):
import math
a, b, h, m = map(int, input().split())
aa = a**2
bb = b**2
cos = math.cos(math.radians(abs(30*(h+m/60) - 6*m)))
ab = 2*a*b*cos

print(math.sqrt( aa + bb - ab))

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

Solution (Python):
import math
a, b, h, m = map(int, input().split())
m=m/60
bd=m*360
h=h+m
ad=h/12*360
d=abs(ad-bd)
ax=a*math.cos(math.radians(ad))
ay=a*math.sin(math.radians(ad))
ax = round(ax, 21)
ay = round(ay, 21)
bx=b*math.cos(math.radians(bd))
by=b*math.sin(math.radians(bd))
bx = round(bx, 21)
by = round(by, 21)





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

Solution (Python):
import math

a, b, h, m = map(int, input().split())
degree_a = (h + m / 60.0) / 12 * 360
degree_b = (m / 60.0) * 360
ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(abs(degree_a - degree_b))))
print(ans)

Solution (Python):
import math

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

deg_m = 360*M/60
deg_h = 360*H/12 + 30*M/60

if deg_h > deg_m: 
    deg = deg_h - deg_m
else:
    deg = deg_m - deg_h

if deg > 180:
    deg = 360 - deg

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

print(C)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
def clockangles(hour, minute):
    ans=abs((hour*30+minute*0.5)-(minute*6))
    return min(360-ans,ans)
degree=math.radians(clockangles(H,M))
print(math.sqrt(A**2+B**2-(2*A*B*math.cos(degree))))

Solution (Python):
import numpy as np

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

angle_m = (360.0 * (H + M / 60.0))%  360
angle_h = 30.0 * (H + M / 60.0)

angle = abs(angle_m - angle_h)

x2 = A ** 2 + B ** 2 - 2.0 * A * B * np.cos(angle * np.pi / 180.0)

x = np.sqrt(x2)

print(x)

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

t = h % 12
import math
ts = m / 60
xs = b * math.sin(math.pi*2*ts)
ys = b * math.cos(math.pi*2*ts)
tl = (t*60+m) / (12*60)
xl = a * math.sin(math.pi*2*tl)
yl = a * math.cos(math.pi*2*tl)
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.pi*2*(ts-tl))))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
kA = (60*H+M)/2
kB = M*6

kAB = min(abs(kA-kB), 360-abs(kA-kB))

if kAB == 0:
    print(abs(A-B))
    exit()
elif kAB == 180:
    print(A+B)
    exit()

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

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

hh=30*h+30*m/60
mh=6*m
re=math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(hh-mh)))
print(re)

Solution (Python):
import math

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

hk=(h*60+m)*0.5
mk=6*m

f=a**2+b**2-2*a*b*math.cos(math.radians(min(abs(hk-mk),360-abs(hk-mk))))
print(math.sqrt(f))

Solution (Python):
import math

tmp=input().split(" ")
tyousin=int(tmp[0])
tansin=int(tmp[1])
time_hour=int(tmp[2])
time_min=int(tmp[3])

long_kaku=2*math.pi*(time_min/60)
min_kaku=2*math.pi*((60*time_hour + time_min)/720)
angle=long_kaku-min_kaku

print(((tansin*math.sin(angle))**2 + (tyousin-(tansin*math.cos(angle)))**2)**0.5)

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

Solution (Python):
import math
a,b,h,m = map(int,input().split())
if h == 0 and m >= 30: h = 12
if m == 0 and m >= 6: m = 60
kakudo = abs(h / 12 + m / 720 - m / 60)
co = math.cos(kakudo * math.pi * 2)
ans = a**2 + b**2 - 2 * a * b * co
print(math.sqrt(ans))

Solution (Python):
import math
def main():
  a, b, h, m = map(int, input().split())
  rad = abs((h*60+m)*0.5 - m * 6)
  temp = abs(360-rad)
  if rad > temp:
    rad = temp
  
  rad = math.radians(rad)
  ans = math.sqrt((a ** 2) + (b ** 2) - 2 *a*b*math.cos(rad))
  print(ans)
  

if __name__ == '__main__':
  main()

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

theta_b = M*6
theta_a = (H*60+M)*0.5
theta = theta_b - theta_a
if theta > 180:
    theta = 360 - theta

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

Solution (Python):
import math

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

pi = math.pi

Hpi = (pi/6)*H + (pi/6)*(M/60)
Mpi = (2*pi)*(M/60)

Rpi = Hpi - Mpi

result = math.sqrt( A**2 + B**2 -2*A*B*math.cos(Rpi) )

print(result)

Solution (Python):
import math

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

angle = abs(30*h + 0.5*m - 6*m)
dangle = angle if angle <= 180 else 360 - angle
d = math.sqrt(a**2 + b**2 - 2*a*b * math.cos(math.radians(dangle)))
print(d)

Solution (Python):
import math

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

t = abs(6*m - 30*h - 0.5*m)

l = math.sqrt(a**2 + b**2 -2*a*b*math.cos(math.radians(t)))

print(l)

Solution (Python):
import math

A,B,H,M=map(int,input().split())
res = float(0)
deg_A = math.pi * (H+M/60) /6
deg_B = math.pi * M/30 
deg_X = abs(deg_A-deg_B)
if deg_X > math.pi:
  deg_X = 2 * math.pi - deg_X
c = 2 * A*B*math.cos(deg_X)
d = A*A + B*B - c
res = d**0.5
print(res)

Solution (Python):
import numpy as np

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

angle_m = (360.0 * (H + M / 60.0))%  360
angle_h = 30.0 * (H + M / 60.0)

angle = abs(angle_m - angle_h)

x2 = A ** 2 + B ** 2 - 2.0 * A * B * np.cos(angle * np.pi / 180.0)

x = np.sqrt(x2)

print(x)

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

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

theta = abs(short_angle-long_angle)
if theta>=180:
    theta = 360-theta

import math
distance = A**2 + B**2 - (2*A*B * math.cos(math.radians(theta)))
distance = abs(math.sqrt(distance))

print(distance)

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

def kakudo(type):
    if type=="n":
        return N*6
    elif type=="n2":
        return abs(360-N*6)
    else:
        return (H*30)+(N*(1/2))

ans=(A**2)+(B**2)-2*A*B*math.cos(math.radians((abs(kakudo("n")-kakudo("h")))))
ans2=(A**2)+(B**2)-2*A*B*math.cos(math.radians((abs(kakudo("n2")-kakudo("h")))))

print(math.sqrt(ans))

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

Solution (Python):
import math

def cal_edge(cosA, b, c):
    return math.sqrt(b*b + c*c - 2 * b * c * cosA)

A, B, H, M = map(int, input().split())
minute = 60 * H + M

b_angle = (360 * M) / 60
a_angle = (360 * minute) / (60*12)

degree = math.fabs(a_angle - b_angle)

if degree > 180:
    degree = 360 - degree

cos = math.cos(math.radians(degree))

print(cal_edge(cos, A, B))

Solution (Python):

import math


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


A_RAD = float((H*60+M)/720*2*math.pi)
B_RAD = float(M/60*2*math.pi)
AB_RAD = A_RAD - B_RAD

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

print(C)

Solution (Python):

import numpy as np

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

hun = 60*H+M

state_zisin = hun/720
state_hunsin = (hun%60)/60

kakudo = min(abs(state_zisin-state_hunsin), 1-abs(state_zisin-state_hunsin))
pi = 3.141592653589793238462643383279
w = kakudo*2*pi
c = (A**2+B**2-2*A*B*np.cos(w))**(0.5)
print("{}".format(c))

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

a = (H / 6 + M / 360) * math.pi
ax = math.cos(a) * A
ay = math.sin(a) * A

b = M / 30 * math.pi
bx = math.cos(b) * B 
by = math.sin(b) * B

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

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

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

alpha = 0.5 * (60 * H + M)
beta = 6 * M
x = abs(beta - alpha)
if x > 180:
  x = 360 - x
rad = np.pi * x / 180
cos = np.cos(rad)
ans = math.sqrt(A**2 + B**2 - 2 * A * B * cos)
print(ans)

Solution (Python):
import math
if __name__=="__main__":
    
    A, B, H, M = map(int, input().split(' '))

    total_min = H*60 + M
    A_rad = 2*math.pi/720 * total_min
    B_rad = 2*math.pi/60 * M
    angle = A_rad-B_rad
    length_pow = A**2 + B**2 - 2*A*B*math.cos(angle)
    print(length_pow**(1/2))