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
import sys

def calc_clock_angle(h, m):
    m_angle = (360 / 60) * m
    h_angle = (360 / 12) * h + ((360 / 12) / 60 ) * m
    angle = abs(m_angle - h_angle)
    if angle > 180:
        return 360 - angle
    else:
        return angle
    pass

a, b, h, m = map(int, input().split())
if h == 12 and m == 0:
    print(abs(a - b))
    sys.exit()

angle = calc_clock_angle(h, m)

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

Solution (Python):
import math


def cosine_theorem(A: int, B: int, theta: float)->float:
    return math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(theta))


def clock_angle(hour: int, minute: int)->float:
    long_rad = (math.pi / 360) * (hour * 60 + minute)
    short_rad = (math.pi / 30) * minute
    diff_rad = abs(long_rad - short_rad)

    while diff_rad > 2*math.pi:
        diff_rad -= 2*math.pi

    return diff_rad


def colon(A: int, B: int, H: int, M: int)->float:
    theta = clock_angle(H, M)
    
    return cosine_theorem(A, B, theta)


if __name__ == "__main__":
    A, B, H, M = map(int, input().split())
    ans = colon(A, B, H, M)
    print(ans)

Solution (Python):
import math

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


a_k = 30*h + (30*m/60)
b_k = 6*m

k = abs(a_k - b_k)

if k > 180:
    k = 360 - k

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

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

theta1 = math.radians(90 - 0.5 * (h * 60 + m))
theta2 = math.radians(90 - 6 * m)

y1 = a * math.sin(theta1)
x1 = a * math.cos(theta1)

y2 = b * math.sin(theta2)
x2 = b * math.cos(theta2)

print(math.sqrt((x1 - x2)**2 + (y1 - y2)**2))

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


def main():
    A, B, H, M = [int(x) for x in stdin.readline().rstrip().split()]
    h_rad = 2 * pi * (360 * (H * 60 + M) / 720) / 360
    m_rad = 2 * pi * (360 * M / 60) / 360
    if h_rad < m_rad:
        rad = m_rad - h_rad
    else:
        rad = h_rad - m_rad
    ans = (A ** 2 + B ** 2 - 2 * A * B * cos(rad)) ** 0.5
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import math
a, b, h, m = map(int, input().split())
t_a = 0.5*(h*60+m)
t_b = 6*m
t = (t_a - t_b)
if t > 180:
    t = 360 - t
c = math.cos(t*2*math.pi/360.0)
print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * c), end="")

Solution (Python):

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

tm = 60*H + M


Dji = 0.5 * tm
Dhu = 6 * tm

'''

Dji2 = Dji % 180
Dhu2 = Dhu % 180



kaku = abs(Dji2 - Dhu2)

'''
Dji2 = Dji % 360
Dhu2 = Dhu % 360


if abs(Dji2 - Dhu2) <=180:
    kaku = abs(Dji2 - Dhu2)
else:
    kaku = 360 - abs(Dji2 - Dhu2)



if kaku ==0:
    out = B - A

if kaku == 180:
    out = B + A
else:
    out = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(kaku)))


print(out)

Solution (Python):
import math
import sys
import numpy
import decimal

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

sita = abs((h / 12 * 360+m/60*30) - (m / 60 * 360))

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

ans = numpy.sqrt((a * a) + (b * b) - (2 * a * b*math.cos(math.radians(sita))))
print(decimal.Decimal(ans))

Solution (Python):
import math

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

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

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

aaa = abs((60*h+m)*0.5 - m*6)
if aaa > 180:
    aaa = 360 - aaa
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(aaa))))

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


perm = (m / 60) * 360

rh = (h / 12) * 360 + (m / 60) * 360 / 12





deg = min(abs(perm - rh), 360 - abs(perm - rh))

rdeg = math.pi / 180 * deg

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

print(ans)

Solution (Python):
import math

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

Md = M * 360 / 60
Hd = H * 30 + M * 30 / 60

MHd = abs(Md - Hd)

if MHd > 180 :
    MHd = 360 - MHd

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


print (math.sqrt(ans))

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


hour = m * (360 // 60)
minutes = h * (360 // 12) + (0.5 * m)

angle = 0
if abs(hour - minutes) > 180:
    angle = 360 - (abs(hour - minutes))
else:
    angle = abs(hour - minutes)

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

print(math.sqrt(ans))

Solution (Python):

import sys
from math import sin, cos, pi, sqrt
import bisect
sys.setrecursionlimit(10 ** 9)
inf = float("inf")
readline = sys.stdin.buffer.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
nt = lambda: tuple(map(int, readline().split()))

def main():
    A, B, H, M = nm()
    theta1 = 2 * pi * (H / 12 + M / 720)
    theta2 = 2 * pi * M / 60

    ans = A ** 2 + B ** 2 - 2 * A * B * cos(abs(theta2 - theta1))
    print(sqrt(ans)) 


if __name__ == '__main__':
    main()

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



l = 360*M/60
s = 30*H+30*M/60
angle = abs(s-l)
if abs(s-l) >= 180:
    angle = min(s,l)+360-max(s,l)
    

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

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

hrad, mrad = math.pi * (60 * h + m) / 360, math.pi * m / 30
rad = min(abs(hrad - mrad), 2*math.pi - abs(hrad - mrad))

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

Solution (Python):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m,a,b = map(int,input().split())
ab = a * 60 + b
A = ab/2
B = b*6
AB = abs(-B+A) 
theta = min(360-AB,AB)


print(math.sqrt((n**2 + m ** 2 - 2*n*m*math.cos(math.radians(theta)))))

Solution (Python):
import math

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

m = M * 6
h = H * 30 + M / 2 

ms = B * math.sin(math.radians(m))
mc = B * math.cos(math.radians(m))
hs = A * math.sin(math.radians(h))
hc = A * math.cos(math.radians(h))

ans = ((ms - hs) ** 2 + (mc - hc) ** 2) ** 0.5

print(ans)

Solution (Python):

import collections
import itertools as it
import math

 


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





mr = (m / 60) * 360
hr = ((h * 60 + m) % 720 / 720) * 360

r = abs(hr - mr)

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

Solution (Python):
import math

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

angle_H = 30 * H + 0.5 * M
angle_M = M * 6

diff_angle = abs(angle_H - angle_M)

if diff_angle >= 180:
    diff_angle =  360 - diff_angle
    
    
C2 = A**2 + B**2 - 2*A*B*math.cos(math.radians(diff_angle)) 

print(math.sqrt(C2))

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

hour = H*0.5*60
mini = M*5.5
d = abs(hour-mini)
ans = A**2 + B**2 - 2 * A * B * math.cos(math.radians(d))
print(math.sqrt(ans))

Solution (Python):
import sys
import math

def IL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def main():
	a, b, h, m = IL()
	h_angle = (h + m / 60) / 12 * 2 * math.pi
	m_angle = m / 60 * 2 * math.pi
	angle = abs(h_angle - m_angle)
	l = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(angle))
	
	print(l)

if __name__ == "__main__":
	main()

Solution (Python):
import math
a,b,h,m=map(int,input().split())
def crad(x):
    return 2*math.pi*x/360%(2*math.pi)
ad=30*h+m/2
bd=6*m
ad=crad(ad)
bd=crad(bd)
sa=min(abs(ad-bd),abs(bd-ad))
print(math.sqrt((a**2+b**2-2*a*b*math.cos(sa))))

Solution (Python):
import math

in_str = input()

in_arr = in_str.split()

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

AM = 60 * H + M

X = math.sqrt(A*A + B*B - 2 * A * B * math.cos((math.pi * 11 * AM)/360))

print(X)

Solution (Python):
import math
N = [int(e) for e in input().split()]
a = (math.pi/360)*(60*N[2] + N[3])
b = (math.pi/30)*N[3]
if(a>b):
    ans = math.sqrt(N[0]**2 + N[1]**2 - 2*N[0]*N[1]*math.cos(a-b))
else:
    ans = math.sqrt(N[0]**2 + N[1]**2 - 2*N[0]*N[1]*math.cos(b-a))
print('{:.020f}'.format(ans))

Solution (Python):
import math


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

kaku = abs((h+m/60)*5+-m)*6
angle = min(kaku, 360-kaku)
cos = math.cos(math.radians(angle))

ans2 = a**2 + b**2 - 2*a*b*cos

print(math.sqrt(ans2))

Solution (Python):

import math 














mod = 998244353
INF = 1<<29
lINF = 1<<35

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

def main():
    a,b,h,m = readInt()
    v1 = 30
    v2 = 6
    r1 = h * v1 + (m / 60) * v1
    r2 = m * v2
    r = abs(r1-r2)
    if r>180:
        r = 360 - r
    ans = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(r)))
    print(ans)
    return

if __name__=='__main__':
    main()

Solution (Python):
import math
import sys
import numpy
import decimal

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

sita = abs((h / 12 * 360+m/60*30) - (m / 60 * 360))

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

ans = numpy.sqrt((a * a) + (b * b) - (2 * a * b*math.cos(math.radians(sita))))
print(decimal.Decimal(ans))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
l = m * 6
s = m * 0.5 + h * 30
th = abs(l - s)
if th == 0:
    print('{:.20f}'.format(abs(a - b)))
    exit()
elif th == 180:
    print('{:.20f}'.format(a + b))
    exit()
if th >= 180:
    th = 360 - th
cos = math.cos(math.radians(th))
ans = a**2 + b**2 - 2 * a * b * cos
print('{:.20f}'.format(math.sqrt(ans)))

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

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

rad = abs((60*h-11*m) / 360)
rad = rad * pi

print(sqrt(a**2 + b**2 - 2*a*b*cos(rad)))

Solution (Python):

import math

def solve(a: int, b: int, h: int, m: int) -> float:
    th1 = (h * 60 + m) / (12 * 60) * 2 * math.pi
    th2 = m / 60 * 2 * math.pi
    dy = a * math.sin(th1) - b * math.sin(th2)
    dx = a * math.cos(th1) - b * math.cos(th2)
    return math.sqrt(dy ** 2 + dx ** 2)


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

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

pos_long = [B * math.sin(M / 60  * 2 * math.pi), B * math.cos(M / 60  * 2 * math.pi)]
pos_short = [A * math.sin((H * 60 + M) / 720  * 2 * math.pi), A * math.cos((H * 60 + M) / 720 * 2 * math.pi)]

print(math.sqrt((pos_long[0] - pos_short[0]) ** 2 + (pos_long[1] - pos_short[1]) ** 2))

Solution (Python):
import math
a, b ,h, m = map(int,input().split())
ra = (h * (360/12)) + m * 1/2
rb = m * (360/60)
ang = abs(rb - ra)
min(ang, (360-ang))

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

Solution (Python):
import math

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

h = h * 30 + (m/2)

m = m * 6

if h < m:
    x = m - h
elif m < h:
    x = h - m
else:
    x = 0

if x == 0:
    if a > b:
        print(a-b)
    elif b > a:
        print(b-a)
    else:
        print(0)
elif x == 180:
    print(a+b)
else:
    cosx = math.cos(math.radians(x))
    ans = math.sqrt(a**2 + b**2 - (2 * a * b * cosx))
    print(ans)

Solution (Python):
import math
import numpy as np
a, b, h, m = map(int, input().split())
long_speed = 6*m
short_speed = 30*h + m/2
theta = abs(long_speed - short_speed)
if theta > 180:
    theta = 360 - theta
c = a*a + b*b - 2*a*b*math.cos(math.radians(theta))
c = np.sqrt(c)
print(c)

Solution (Python):


import math


def main():
    a, b, h, m = map(int, input().split())
    rot_hr = (60 * h + m) / 720 * 2 * math.pi
    rot_mn = m / 30 * math.pi
    hr_x = a * math.sin(rot_hr)
    hr_y = a * math.cos(rot_hr)
    mn_x = b * math.sin(rot_mn)
    mn_y = b * math.cos(rot_mn)
    print(f'{math.sqrt((hr_x - mn_x) ** 2 + (hr_y - mn_y) ** 2): .9f}')


if __name__ == "__main__":
    main()

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

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

if M == 0:
    m = 360
else:
    m = 6 * M

h = 30 * H + 0.5 * M


c = abs(h - m)

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

C = (A ** 2 + B ** 2 - 2*A*B*cos) ** 0.5

print(C)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
omega_h = 360 / (12*60)
omega_m = 360 / 60

min_sum_h = (H*60 + M) * omega_h
min_sum_h = min_sum_h % 360
min_sum_m = M * omega_m

if min_sum_h - min_sum_m > 180:
    omega = 360 - (min_sum_h - min_sum_m)
else:
    omega = min_sum_h - min_sum_m

cos_omega = math.cos(math.radians(omega))
res = (A**2 + B**2 - 2*A*B*cos_omega)**0.5
print("{:.20f}".format(res))

Solution (Python):
import math

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

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

theta_degree = abs(hour_degree - minute_degree)
theta_rad = math.radians(theta_degree)

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

Solution (Python):
A,B,H,M = map(int,input().split())
minutes = H*60 + M
angle_pm_h = 360 / (12 * 60)
angle_pm_m = 360 / 60
angle_h = angle_pm_h * minutes
angle_m = angle_pm_m * M % 360
angle = angle_h - angle_m
import math
ans = math.sqrt(A*A + B*B - 2 * A * B * math.cos(math.radians(angle)))
print(ans)

Solution (Python):
import math

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

B_ang = 6*M
A_ang = 30*H + (0.5*M)
AB_cos = math.cos(math.radians(min(360 - abs(A_ang - B_ang), abs(B_ang - A_ang))))
ans = math.sqrt(A**2 + B**2 - (2*A*B*AB_cos))

print(ans)

Solution (Python):

import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache

readline=sys.stdin.readline
sys.setrecursionlimit(2000000)

alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def pm(x):
    return x//abs(x)

def main():
    A,B,H,M=map(int,input().split())
    md=360/60
    hd=360/(60*12)
    MD=md*M
    HD=hd*(H*60+M)
    kaku=min(max(MD,HD)-min(MD,HD),360-(max(MD,HD)-min(MD,HD)))
    ans=A**2+B**2-2*A*B*math.cos(math.radians(kaku))
    ans=math.sqrt(ans)
    print(ans)

main()

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

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

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

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

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

h_kaku = 30 * h + (m / 2)
m_kaku = 6 * m

sa_kaku = h_kaku - m_kaku if h_kaku >= m_kaku else m_kaku - h_kaku

if sa_kaku > 180:
    sa_kaku = 360 - sa_kaku

if sa_kaku == 180:
    ans = a + b
elif sa_kaku == 0:
    if a >= b:
        ans = a - b
    else:
        ans = b - a
else:
    ans = a**2 + b**2 - 2*b*a*math.cos(math.radians(sa_kaku))
    ans = math.sqrt(ans)

print(ans)

Solution (Python):
import math

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

if n > 12.0:
    n -= 12.0


n_angle = n * 30.0 + m * 0.5
m_angle = m * 6.0
angle = 0.0

if n_angle < m_angle:
    if (m_angle - n_angle) < 360.0 - (m_angle - n_angle):
        angle = m_angle - n_angle
    else:
        angle = 360.0 - (m_angle - n_angle)
else:
    if (n_angle - m_angle) < 360.0 - (n_angle - m_angle):
        angle = n_angle - m_angle
    else:
        angle = 360.0 - (n_angle - m_angle)
    
ans = a*a + b*b - 2.0*a*b*(math.cos(math.radians(angle)))
print(math.sqrt(ans))

Solution (Python):
import math

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

ji = 360/12
fun = 360/60

hh = (ji * h) + (ji/60 * m)
mm = fun * m

if hh > mm:
    c = hh-mm
else:
    c = mm-hh

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

print(str(ans))

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

x = ((a*math.cos(math.pi/6*(h+m/60))-b*math.cos(math.pi/30*m))**2 + (a*math.sin(math.pi/6*(h+m/60))-b*math.sin(math.pi/30*m))**2 )**(1/2)

print(x)

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


th_a = 360/12 * h + 360/12*m/60
th_b = 360*m/60

ab_th = abs(th_a - th_b)
if ab_th > 180:
    ab_th = 360 - ab_th

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

Solution (Python):
import math

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

htom = h * 60 + m
hkaku = htom / 2
mkaku = m * 6
aida = abs(hkaku - mkaku)
if aida > 180:
    aida = 360 - aida
ans = a * a + b * b - 2 * a * b * math.cos(math.radians(aida))
ans = math.sqrt(ans)
print(ans)

Solution (Python):
A, B, H, M = (int(i) for i in input().split())

from math import radians, cos, sqrt
h_degree = (360/12) * H + (360/12) * (M/60)
m_degree = (360/60) * M

diff_degree = abs(m_degree-h_degree)
use_degree = min(diff_degree, 360-diff_degree)

ans = A**2 + B**2 - (2*A*B*cos(radians(use_degree)))
print(sqrt(ans))

Solution (Python):
import sys
import math
sys.setrecursionlimit(10**6)


def main(input, print):
    a, b, h, m = map(int, input().split())
    ar = (h*30+(m*0.5)) * (math.pi/180)
    ax = -a*math.sin(ar)
    ay = a*math.cos(ar)
    br = m*6 * (math.pi/180)
    bx = -b*math.sin(br)
    by = b*math.cos(br)
    print(math.sqrt((bx-ax)**2+(by-ay)**2))


if __name__ == '__main__':
    main(sys.stdin.readline, print)

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

h_d = 30 * H + M / 2
m_d = 6 * M

if h_d >= m_d:
    D = h_d - m_d
else:
    D = m_d - h_d

if D > 180:
    D = 360 - D

if D == 0:
    ans = abs(B - A)
elif D == 180:
    ans = B + A
else:
    ans_sq = A*A + B*B - 2*A*B*math.cos(math.radians(D))
    ans = math.sqrt(ans_sq)
print(ans)

Solution (Python):
import math

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

print(math.sqrt(a**2+b**2-2*a*b*math.cos((1/12)*(11*m/60-h)*2*math.pi)))

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

Solution (Python):
import math

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

h = (0.5 * (H * 60 + M)) % 360
m = M * 6

r = math.radians(abs(h - m))

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

print(res)

Solution (Python):
def calculAngle(h,m):          
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    h_angle = 0.5 * (h * 60 + m) 
    m_angle = 6 * m 
    angle = abs(h_angle - m_angle) 
    angle = min(360 - angle, angle) 
    return angle 
import math
A,B,H,M = map(int,input().split())
ans = math.sqrt(A**2 + B ** 2 - 2 * A * B * math.cos(math.radians(calculAngle(H,M))))
print(ans)

Solution (Python):

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


short = H * 30 + M * (30/60)
loong = M * 6
deg = abs(short - loong)
if deg > 180:
    deg= 360 - deg


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

Solution (Python):
import math

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

h_speed = 2 * math.pi / (12 * 60)
m_speed = 2 * math.pi / 60

h_agree = (h_speed * (H * 60 + M)) % (2 * math.pi)
m_agree = (m_speed * (H * 60 + M)) % (2 * math.pi)
true_agree = abs(h_agree - m_agree)
if true_agree >=  math.pi:
     true_agree = 2 * math.pi - true_agree


l_distance = max(A,B)
s_distance = min(A,B)

answer = ((math.sin(true_agree) * s_distance) ** 2 + (l_distance - math.cos(true_agree) * s_distance) ** 2) ** 0.5

print(answer)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
x1 = a*math.cos(math.pi/2 - (h+m/60)*math.pi/6)
y1 = a*math.sin(math.pi/2 - (h+m/60)*math.pi/6)
x2 = b*math.cos(math.pi/2 - m*math.pi/30)
y2 = b*math.sin(math.pi/2 - m*math.pi/30)
d = math.sqrt((x1-x2)**2+(y1-y2)**2)
print(d)

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




def yogen_teiri(A, B, ang):
    lenAB = np.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(ang)))
    return lenAB

angA = H*30+M*0.5
angB = M*6

if angA > angB:
    angAB = min(angA-angB, 360-(angA-angB))
    lenAB = yogen_teiri(A, B, angAB)
elif angB > angA:
    angAB = min(angB-angA, 360-(angB-angA))
    lenAB = yogen_teiri(A, B, angAB)
else:
    lenAB = np.abs(A-B)

print(lenAB)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
hdeg = 30*h+m*0.5
mdeg = 6*m
if hdeg >=mdeg:
    deg = hdeg-mdeg
else:
    deg = mdeg-hdeg
bb = b*math.sin(math.radians(deg))
aa = a-b*math.cos(math.radians(deg))
print(math.sqrt((aa**2)+(bb**2)))

Solution (Python):
import math

a,b,h,m = map(int,input().split())
ang_a = h/12 + m/60/12
ang_b = m/60
ang = min(math.fabs(ang_a-ang_b),1-math.fabs(ang_a-ang_b))
ans_s = a**2+b**2-2*a*b*math.cos(2*ang*math.pi)
ans = math.sqrt(ans_s)
print(ans)

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

time = h * 60 + m  
h_theta = (0.50 * time) % 360
m_theta = (6.0 * time) % 360

h_pos = [a * math.cos(math.radians(h_theta)), a * math.sin(math.radians(h_theta))]
m_pos = [b * math.cos(math.radians(m_theta)), b * math.sin(math.radians(m_theta))]

x = abs(h_pos[0] - m_pos[0])
y = abs(h_pos[1] - m_pos[1])

dist = math.sqrt(x ** 2 + y ** 2)

print(dist)

Solution (Python):
import math
A, B,H,M = map(int, input().split())
a=math.pi*2*(H/12)+math.pi*2*(5/60)*(M/60)
b=math.pi*2*(M/60)
Ma=max(a,b)
mi=min(a,b)
kaku=Ma-mi
print((A**2+B**2-2*A*B*math.cos(kaku))**(1/2))

Solution (Python):
import math

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

hour_hand = (60*h+m)/2
minute_hand = 6*m
theta = max(hour_hand, minute_hand) - min(hour_hand, minute_hand)
if theta > 180:
    theta = 360 - theta
theta = math.radians(theta)

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

Solution (Python):
import math

def get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d

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

point_h = [
    a * math.cos(math.radians((90 - 30*h)-m/2.0)),
    a * math.sin(math.radians((90 - 30*h)-m/2.0))
]

point_m = [
    b * math.cos(math.radians(90 - 6*m)),
    b * math.sin(math.radians(90 - 6*m))
]

print(get_distance(point_h[0], point_h[1], point_m[0], point_m[1]))

Solution (Python):
import math

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

ang_a = (h+m/60)/12
ang_b = m/60
ang = ang_a - ang_b if ang_a - ang_b <= 0.5 else ang_b - ang_a
theta = ang * 2 * math.pi
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(theta)))

Solution (Python):
import math

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

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

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

Solution (Python):
import math
lis = list(map(int, input().split()))
a = lis[0]
b = lis[1]
h = lis[2]
m = lis[3]
if(h / 12 == 0 and
   m / 60 == 0):
  len = abs(a-b)
else:
  hdeg = 30 * h + m / 2
  mdeg = 6 * m
  deg = abs(hdeg - mdeg)
  len = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(deg)))
print(len)

Solution (Python):
import math

a,b,h,m=map(float,input().split())
hs=(h*60+m)*360/(12*60)
ms=m*360/60
angle=hs-ms
if angle>=180:
    angle=360-angle
ans=a**2+b**2-2*a*b*math.cos(math.radians(angle))
ans=math.sqrt(ans)
print("{:.10f}".format(ans))

Solution (Python):
import math

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

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

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

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")

from math import pi, sin, cos, sqrt

def solve(a, b, h, m):
    h = h % 12
    m = m % 60

    hr = h / 12 * 2 * pi + m / 60 / 12 * 2 * pi
    mr = m / 60 * 2 * pi

    hr += 2*pi + pi/4
    mr += 2*pi + pi/4

    hr %= 2*pi
    mr %= 2*pi
    return sqrt(pow(sin(hr)*a - sin(mr)*b,2) + pow(cos(hr)*a - cos(mr)*b,2))



if __name__ == "__main__":
    a, b, h, m = arr_in()
    out(solve(a, b, h ,m))

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

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

Solution (Python):
import math

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

h_angle = h * 30 + m / 2
m_angle = m * 6

angle_rd = math.radians(abs(h_angle - m_angle))

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

Solution (Python):
import math

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


M_A = M / 60 * 360 * math.pi / 180
Minx = B * math.cos(M_A)
Miny = B * math.sin(M_A)

H = H
if H >= 12: 
    H -= 12
H = H + M / 60

H_A = H / 12 * 360 * math.pi / 180

Hourx = A * math.cos(H_A)
Houry = A * math.sin(H_A)

result = math.sqrt(pow((Minx - Hourx),2) + pow((Miny - Houry), 2))
print(result)

Solution (Python):
import math

(a, b, h, m) = [float(s) for s in input().split()]

p_2 = 2 * math.pi

h_deg = 360 / 12 * h + (30 / 60 * m)
m_deg = 360 / 60 * m

diff_rad = (h_deg - m_deg) * math.pi / 180

cos = math.cos(diff_rad)

c_sqr = pow(a, 2) + pow(b, 2) - (2 * a * b * cos)
c = math.sqrt(c_sqr)

print(c)

Solution (Python):
import math


def check(deg):
    if deg > 180:
        return 360 - deg
    else:
        return deg


a, b, h, m = map(int, input().split())
deg_h = 360 * (h / 12) + 360 * 5 / 60 * (m / 60)
deg_m = 360 * (m / 60)

deg = abs(deg_h - deg_m)
deg = check(deg)

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

Solution (Python):


import math

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

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

sr = min(hr, mr)
lr = max(hr, mr)

tr = min(lr - sr, sr + 2 * math.pi - lr)

d = math.sqrt((a * math.cos(tr) - b) ** 2 + (a * math.sin(tr)) ** 2)

print(d)

Solution (Python):
import numpy as np

hour = 30
minute = 6

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

ath = H * hour + M * 0.5
bth = M * minute

ax = np.sin(np.radians(ath)) * A
ay = np.cos(np.radians(ath)) * A

bx = np.sin(np.radians(bth)) * B
by = np.cos(np.radians(bth)) * B

ans = np.sqrt(((max(ax, bx) - min(ax, bx))**2) + ((max(ay, by) - min(ay, by))**2))

print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
hun = 5.5*(H*60+M)
while hun >= 360:
    hun = hun-360
if hun >= 180:
    hun = 360-hun
kotae = math.sqrt((A*A)+(B*B)- (2*A*B*(math.cos(math.radians(hun)))))
print(kotae)

Solution (Python):
import math

a,b,h,m = input().split()
a,b,h,m = int(a),int(b),int(h),int(m)
asin = a * math.sin(math.radians(90-30*h-0.5*m))
acos = a * math.cos(math.radians(90-30*h-0.5*m))
bsin = b * math.sin(math.radians(90-6*m))
bcos = b * math.cos(math.radians(90-6*m))
d = math.sqrt((asin - bsin)**2 + (acos - bcos)**2)
print(d)

Solution (Python):
import math

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

def get_distance(x1, y1, x2, y2):
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
    return d
  
x1 = A * math.cos((30*H + M/2)/360*2*math.pi)
y1 = A * math.sin((30*H + M/2)/360*2*math.pi)
  
x2 = B * math.cos(6*M/360*2*math.pi)
y2 = B * math.sin(6*M/360*2*math.pi)


print(get_distance(x1, y1, x2, y2))

Solution (Python):
import math

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

sita = 0.5 * (h*60 + m)
fai = 6*m
print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(sita) - math.radians(fai))))