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 = list(map(int, input().split()))
pi = 3.141592653589793
angle_M = M * pi / 30
angle_H = H * pi / 6 + angle_M / 12
angle = abs(angle_H - angle_M)
angle = min(angle, 2 * pi - angle)
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle)))

Solution (Python):
import math

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



d = abs(30*h - 5.5*m)
if(d > 180):
    d = 360 - d


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

Solution (Python):


from math import pi
from math import cos
import math


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

    
    return (A**2 + B**2 - 2*A*B*cos(math.radians((60*H-11*M)/2)))**0.5


print(main())

Solution (Python):
import math
a,b,h,m=map(int,input().split())
hkaku=(h+m/60)*30
mkaku=m/60*360
if abs(hkaku-mkaku)>180:
    kakudo=360-abs(hkaku-mkaku)
else:
    kakudo=abs(hkaku-mkaku)

kakudo=math.radians(kakudo)

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

Solution (Python):
import decimal
import math

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

thetaA = 360 * (decimal.Decimal(H/12)+decimal.Decimal(M/(12*60)))
thetaB = 360 * decimal.Decimal(M/60)

AX = A*math.cos(math.radians(thetaA))
AY = A*math.sin(math.radians(thetaA))

BX = B*math.cos(math.radians(thetaB))
BY = B*math.sin(math.radians(thetaB))

print(math.sqrt((AX-BX)**2 + (AY-BY)**2))

Solution (Python):
import math
import sys
def input():
    return sys.stdin.readline().rstrip('\n')

def calc(A, B, H, M):
    a = abs((H * 60 + M) / 720 - M / 60) * 2
    if a > 1:
        a = 2 - a
    return math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(a * math.pi))

    

(A, B, H, M) = tuple([int(s) for s in input().split()])
print(calc(A, B, H, M))

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

dig = abs((30*H+(M/60)*30)-6*M)
dig = min(dig, 360-dig)
rad = math.radians(dig)
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())

a = A*math.cos(2*math.pi* (H+(M/60)) /12)
b = A*math.sin(2*math.pi* (H+(M/60)) /12)
c = B*math.cos(2*math.pi*M/60)
d = B*math.sin(2*math.pi*M/60)
print( ( (a-c)**2+(b-d)**2 ) ** 0.5)

Solution (Python):
import math

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


m_d = 360 * (M / 60)

h_d = 360 * (((60 * H) + M) / (60 * 12))

x = abs(m_d - h_d)
y = 360 - x
C_d = min(x, y)

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

Solution (Python):
import math
a, b, h, m = map(int, input().split())
hang = (h * (360 / 12)) + m * 1/2;
mang = m * (360 / 60);
ang = abs(hang - mang);
if ang>180:
    ang=360-ang
print(math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(math.radians(ang))))

Solution (Python):
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

a,b,h,m = mi()

rad_m = m
rad_h = h*5+5*(m/60)

r = min(abs(rad_m-rad_h),360-abs(rad_m-rad_h))
rad = 360*r/60

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

Solution (Python):
import math

a,b,h,m = map(int,input().split())
s = (60*h + m)*60
s1 = (60*(h-12) + m)*60
sm = 60*m

if h <= 11:
  thetaa = s*(math.pi/(6*3600))
  thetab = (60*m*math.pi)/1800
  theta = abs(thetaa - thetab)
  print(math.sqrt(a**2 + b**2 -2*a*b*math.cos(theta)))
  
else:
  thetaa = s1*(math.pi/(6*3600))
  thetab = (60*m*math.pi)/1800
  theta = abs(theataa - thetab)
  print(math.sqrt(a**2 + b**2 -2*a*b*math.cos(theta)))

Solution (Python):


import numpy as np
pi=np.pi

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

p=int(H)/12+int(M)/60/12
q=int(M)/60
s=abs(p-q)
ans=np.sqrt(int(A)**2+int(B)**2-2*int(A)*int(B)*np.cos(2*pi*s))

print(ans)

Solution (Python):
import math


a,b,h,m = map(int,input().split())
theta_a = (h/12*2+m/60/12*2)*math.pi
theta_b = m/60*2*math.pi

a_x = math.cos(theta_a)*a
a_y = math.sin(theta_a)*a
b_x = math.cos(theta_b)*b
b_y = math.sin(theta_b)*b



res = math.sqrt((a_x-b_x)**2+(a_y-b_y)**2)
print(res)

Solution (Python):
import math

a, b, h, m = map(int, input().split())
x_a = a * math.sin(math.radians((60 * h + m) / 2))
y_a = a * math.cos(math.radians((60 * h + m) / 2))
x_b = b * math.sin(math.radians(6 * m))
y_b = b * math.cos(math.radians(6 * m))
ans = math.sqrt((x_a - x_b) ** 2 + (y_a - y_b) ** 2)
print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split( ))
pi = 2*math.pi
time = H*60. + M
theta_A = (time/720.)*pi
theta_B = (M/60.)*pi
theta = abs(theta_A - theta_B)
if theta >= 180:
    theta = pi - theta
C = A**2 + B**2 - 2*A*B*math.cos(theta)
print(math.sqrt(C))

Solution (Python):
import math
a,b,h,m=list(map(int,input().split()))
angh=(h+m/60)/12*360
angm=m/60*360

AB=min(angh-angm,360-(angh-angm))

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

Solution (Python):
import math
[a, b, h, m] = list(map(int, input().rstrip().split()))
hour_angle = 0.5 * (h * 60 + m)
minute_angle = 6 * m

angle = abs(hour_angle - minute_angle)
angle = min([360 - angle, angle])
angle = angle * math.pi / 180

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

Solution (Python):
import math

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

a_angle = 360 * h /12 + (360 / 12) * m / 60
b_angle = 360 * m / 60
diff_angle = abs(a_angle - b_angle)
ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(diff_angle)))
print (ans)

Solution (Python):

"""
Created on Sun May 17 20:23:09 2020

@author: Kanaru Sato
"""
import math

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

s = a**2+b**2-2*a*b*math.cos(math.pi*(11*m-60*h)/360)
ans = math.sqrt(s)

print(ans)

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

hourDegree = H * 30 + 0.5 * M
hourDegree = hourDegree % 360
minDegree = (H * 60 + M) * 6
minDegree = minDegree % 360

if abs(minDegree - hourDegree) > 180:
    degree = 360 - abs(minDegree - hourDegree)
else:
    degree = abs(minDegree - hourDegree)

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

Solution (Python):
from math import radians, sin, cos
a, b, h, m = [int(x) for x in input().split()]
theta = radians(30 * h + 0.5 * m)
phi = radians(6 * m)
print(((a * sin(theta) - b * sin(phi)) ** 2 +  (a * cos(theta) - b * cos(phi)) ** 2) ** 0.5)

Solution (Python):
import numpy as np

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

h_y = a*np.cos((2*np.pi)*(h*60+m)/(12*60))
h_x = a*np.sin((2*np.pi)*(h*60+m)/(12*60))

m_y = b*np.cos((2*np.pi)*m/60)
m_x = b*np.sin((2*np.pi)*m/60)

ans = np.sqrt((h_y - m_y)**2 + (h_x - m_x)**2)
print(ans)

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

angle_a = 30 * h + 30 * m / 60
angle_b = 360 * m / 60

angle = min(abs(angle_a - angle_b), 360 - abs(angle_a - angle_b))
print(math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(angle))))

Solution (Python):
import numpy as np

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

theta_H = (H/12 + M/60/12) * 2*np.pi
theta_M = M/60 * 2*np.pi
theta = abs(theta_H - theta_M)

len_sq = A**2 + B**2 - 2*A*B*np.cos(theta)
print(np.sqrt(len_sq))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
xa=0.0
xb=0.0
hangle=(h*60+m)/(12*60)
mangle=m/60







ans2=math.sqrt(float(a)**2+float(b)**2-2*float(a)*float(b)*math.cos(2*math.pi*(hangle-mangle)))
print(ans2)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
h%=12
ad=360*(m/60)
bd=360*(h/12)+30*(m/60)
dig=abs(ad-bd)
c=math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(dig)))
print(c)

Solution (Python):
from math import pi, cos

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

theta = (H / 12 + M / 720 - M / 60) * 2 * pi
c2 = A ** 2 + B ** 2 - 2 * A * B * cos(theta)
print(c2 ** 0.5)

Solution (Python):
import math

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

a = (60 * H + M) * 0.5
b = M * 6
c = max(a, b) - min(a, b)
if c > 180:
    c = 360 - c

if c == 180:
    print(A + B)
elif c == 0:
    print(max(A, B) - min(A, B))
else:
    C2 = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(c))
    C = math.sqrt(C2)
    print(C)

Solution (Python):
import math
a, b, h ,m = map(int, input().split())
t = h * 60 + m
ht = 2*math.pi/(12.0*60.0) * t
mt = 2*math.pi/(60.0) * m
x = a**2 + b**2 - 2*a*b*math.cos(abs(mt-ht))
x = math.sqrt(x)
print(x)

Solution (Python):
import math

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

angle_h = h * 30 + m * 0.5
angle_m = m * 6
diff = min(abs(angle_h - angle_m), 360 - abs(angle_h - angle_m))
cos = math.cos(math.radians(diff))
ans = a * a + b * b - 2 * a * b * cos

print(math.sqrt(ans))

Solution (Python):
import sys
import math
from collections import deque
from collections import defaultdict

def main():
    a, b, h, m = list(map(int,sys.stdin.readline().split()))
    
    a_rad = (h/12 + ((5 * m) / pow(60,2))) * 2 * math.pi
    b_rad = float(m/60) * 2 * math.pi
    
    rad_a2b = min(2 * math.pi - abs(a_rad - b_rad), abs(a_rad - b_rad))
    
    c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(rad_a2b))
    print("{:.10f}".format(c))
    return 0

if __name__ == "__main__":
    main()

Solution (Python):
A,B,H,M=map(int,input().split())
import math
fun=60*H+M
SA=5.5 * fun
syuu=SA//360
sa=SA-syuu*360
rad=math.pi * sa /180
C=(A**2 +B**2 -2*A*B* math.cos(rad))**(1/2)
print(C)

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

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

theta = abs(theta_h - theta_m)

dist = pow(a**2 + b**2 - 2*a*b*cos(theta), 1/2)
print(dist)

Solution (Python):
def c_colon():
    import math
    A, B, H, M = [int(i) for i in input().split()]

    choshin_degree = 6 * M
    tanshin_degree = 0.5 * (60 * H + M)

    degree = abs(choshin_degree - tanshin_degree)
    if degree > 180:
        degree = 360 - degree
    theta = math.radians(degree)
    return math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(theta))

print(c_colon())

Solution (Python):
import math
a, b, H, M=map(int,input().strip().split())
H %= 12

short = M*6
long = (H*60+M)/2.0
dif = abs(short-long)
kakudo = min(dif,360-dif)

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

Solution (Python):
from numpy import cos, pi, sqrt
li = list(map(int, input().split()))
A, B, H, M = li[0], li[1], li[2], li[3]

thetaA = pi*(H/6 + M/360)
thetaB = pi*M/30
dtheta = abs(thetaA - thetaB)
if dtheta > pi:
    dtheta = 2*pi - dtheta
x = sqrt(A**2 + B**2 -2*A*B*cos(dtheta))
print(x)

Solution (Python):
from math import sqrt, cos, radians
(a, b, h, m)=[int(x) for x in input().split()]
print(sqrt(a**2+b**2-2*a*b*cos(radians(m*6-(h*60+m)*0.5))))

Solution (Python):
import math

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

X = min(abs(6*M-0.5*(60*H+M)), 360-abs(6*M-0.5*(60*H+M)))
print((A**2+B**2-2*A*B*(math.cos(math.radians(X))))**0.5)

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

pi = math.pi
w_a = pi/360
w_b = pi/30
mins = 60*H + M
rad_a = -w_a * mins
rad_b = -w_b * mins
x_a = A * math.cos(rad_a)
y_a = A * math.sin(rad_a)
x_b = B * math.cos(rad_b)
y_b = B * math.sin(rad_b)
print(math.sqrt((x_a-x_b)**2+(y_a-y_b)**2))

Solution (Python):
import sys
import math


input = sys.stdin.readline


def main():
    ac = (A*math.sin((H*60+M)*math.pi/360.0), A*math.cos((H*60+M)*math.pi/360.0))
    bc = (B*math.sin(M*math.pi/30.0), B*math.cos(M*math.pi/30.0))
    print(((ac[0]-bc[0])**2 + (ac[1]-bc[1])**2)**0.5)


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

Solution (Python):
import math

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

mins = 60 * h + m

short_kaku = mins * 0.5
short_x = a * (math.cos(math.radians(90 - short_kaku)))
short_y = a * (math.sin(math.radians(90 - short_kaku)))

long_kaku = (mins % 60) * 6
long_x = b * (math.cos(math.radians(90 - long_kaku)))
long_y = b * (math.sin(math.radians(90 - long_kaku)))

pre_ans = (short_x - long_x) ** 2 + (short_y - long_y) ** 2
ans = pow(pre_ans, 0.5)

print(ans)

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

p = 2*a*b*math.cos(math.pi*(11*m/360-h/6))


print((a**2+b**2-p)**0.5)

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

hx = math.cos(math.radians(30 * H + (M / 2))) * A
hy = math.sin(math.radians(30 * H + (M / 2))) * A
mx = math.cos(math.radians(6 * M)) * B
my = math.sin(math.radians(6 * M)) * B

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

Solution (Python):
def main():
    import sys
    import math
    def input():
        return sys.stdin.readline()[:-1]
    A,B,H,M=map(int,input().split())
    C=0
    Hsita=360*(H/12)+30*(M/60)
    Msita=360*(M/60)
    sita=Hsita-Msita
    if sita>180:
        sita=360-sita
    C=math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(sita)))

    if sita==180:
        C=A+B
    
    print(C)
    

    

        


if __name__ == '__main__':
    main()

Solution (Python):
import math

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

hdeg = math.radians(360 / 12 / 60)
mdeg = math.radians(360 / 60)

hdeg *= 60 * h + m
mdeg *= m

deg = abs(hdeg - mdeg)


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

Solution (Python):
import math

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

theta = H * 30 + (M / 60) * 30 - M * 6
theta = theta + 360 if theta < 0 else theta
theta = theta - 360 if theta > 360 else theta

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

Solution (Python):
import math
a, b, h, m = map(int,input().split())
h_angle = (h+m/60)/12
m_angle = m/60
diff_angle = abs(h_angle-m_angle)*360
ans = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(diff_angle)))
print(ans)

Solution (Python):
import math

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

minn=h*60+m

deg_l=6*minn
deg_s=0.5*minn

delta=5.5*minn

c2=a**2+b**2-2*a*b*math.cos(math.radians(delta))



c=math.sqrt(c2)
print(c)

Solution (Python):
import math
a, b, h, m = list(map(int, input().split()))
th = abs(30 * h + 0.5 * m - 6 * m)
if th > 180:
    th -= 360
    th = abs(th)
rad = math.radians(th)
d = pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(rad)
d = pow(d, 0.5)
print(d)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor, cos, sqrt, pi
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline









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

a = (H * 60 + M) * 0.5
b = ((H * 60 + M) * 6) % 360

t = max(a, b) - min(a, b)
t = min(abs(360 - t), t)

p = A ** 2 + B ** 2

if t == 90:
    print(sqrt(p))
    exit(0)

print(sqrt(p - 2 * A * B * cos(t * pi / 180)))

Solution (Python):
import math

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

ka_a = ((H/12) * 360) + (30*(M/60))
ka_b = M/60 * 360

kakudo = max(ka_a, ka_b) - min(ka_a, ka_b)
kakudo = min(kakudo, (360-kakudo))
cos = math.cos(math.radians(kakudo))

if kakudo==180:
    print(A+B)
    exit()

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

print(math.sqrt(ans))

Solution (Python):


import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

A, B, H, M = LI()

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

cosa = math.cos(math.radians(abs(h-m)))
c2 = A**2 + B**2 - (2*A*B*cosa)

print(math.sqrt(c2))

Solution (Python):
import numpy as np
import math

a,b,h,m=map(int,input().split(' '))
a_angle=(360/12)*(h+m/60)
b_angle=(360/60)*m
theta=math.radians(abs(a_angle - b_angle))
print((a**2+b**2-2*a*b*np.cos(theta))**(1/2))

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

t1 = math.pi*M/30
t2 = math.pi*(H/6 + M/360)

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

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

def readinput():
    a,b,h,m=list(map(int,input().split()))
    return a,b,h,m

def main(a,b,h,m):
    tmin=h*60+m
    u=tmin*2*pi/(12*60)
    t=m*2*pi/60
    dist=sqrt(
        (a*cos(u)-b*cos(t))**2
        +(a*sin(u)-b*sin(t))**2
        )
    return dist

if __name__=='__main__':
    a,b,h,m=readinput()
    ans=main(a,b,h,m)
    print('{:.10f}'.format(ans))

Solution (Python):
import math

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

Arad = (60.0 * H + M) * 2 * math.pi / (12.0 * 60.0)
Brad = M * math.pi / 30.0


Ax = A * math.cos(-Arad+ math.pi/2)
Ay = A * math.sin(-Arad+math.pi/2)
Bx = B * math.cos(-Brad+math.pi/2)
By = B * math.sin(-Brad+math.pi/2)

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

Solution (Python):
import math
A,B,H,M = map(int,input().split())
s = H * 60 + M
Md = (M/60) * 360
Hd = (s/(12 * 60)) * 360
a = abs(Md-Hd)
if a > 180:
    a = 360 - a
a = math.radians(a)
a2 = (A**2+B**2)-(2*B*A*math.cos(a))
print(math.sqrt(a2))

Solution (Python):
import math


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

h_deg = 30 * h + 0.5 * m
m_deg = 6 * m
diff_rad = math.radians(abs(h_deg - m_deg))
print((a ** 2 + b ** 2 - 2 * a * b * math.cos(diff_rad)) ** 0.5)

Solution (Python):
import numpy as np
if __name__ == "__main__":
    A, B, H, M = map(int, input().split())
    a = 0.5 * (60 * H + M) 
    b = 6 * M 
    
    a = a * np.pi / 180
    b = b * np.pi / 180
    
    

    c1 = np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(a-b))
    c2 = np.sqrt(A**2 + B**2 - 2 * A * B * np.cos(b-a))
    print(min(c1, c2))

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

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

if h1 >= m1:
    c=h1-m1
    if c >=180:
        c=360-c
else:
    c=m1-h1
    if c >=180:
        c=360-c

rad=math.radians(c)

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

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

theta=(11*m-60*h)*math.pi/360
x=math.sqrt(a**2+b**2-2*a*b*math.cos(theta))
print(x)

Solution (Python):
import math

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

lo=(60*H+M)/2

sh=M*6

C = float(lo)-float(sh)

sin=math.cos(math.radians(C))

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

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

Solution (Python):

import math



if(__name__ == '__main__'):
    
    a, b, h, m = map(int, input().split(" "))

    h %= 12
    minute = h * 60 + m

    a_rad = (2.0 * math.pi * minute) / (60 * 12)
    b_rad = (2.0 * math.pi * m) / 60

    a_x = a * math.cos(a_rad)
    a_y = a * math.sin(a_rad)
    b_x = b * math.cos(b_rad)
    b_y = b * math.sin(b_rad)

    x = a_x - b_x
    y = a_y - b_y

    ans = math.sqrt(x*x + y*y)

    print(ans)

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

B = (math.pi)*m/30
A = (math.pi)*h/6 + B/12

print(((a**2) + (b**2) - 2*a*b*(math.cos(B-A)))**(1/2))

Solution (Python):
import math

data = list(map(int, input().split()))
da = (data[2] + data[3] / 60) / 12
db = data[3] / 60
angle = abs(da - db) * 2 * math.pi
c = math.sqrt(data[0] * data[0] + data[1] * data[1] - 2 * data[0] * data[1] * math.cos(angle))
print(c)

Solution (Python):




def input_int():
    return int(input())



def int1(x):
    return int(x) - 1



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



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


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

    
    
    tyoshin_do = (float(h) * 30.0) + (0.5 * m)
    
    tanshin_do = (6.0 * float(m))
    
    do = abs(tyoshin_do - tanshin_do)

    import math

    return math.sqrt(math.pow(float(a), 2) + math.pow(float(b), 2) - (2.0 * a * b) * math.cos(math.radians(do)))


if __name__ == "__main__":
    print(main())

Solution (Python):
import math

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


zisin = H*30 + (M/60)*30
hunsin = float(M*6)
sa = abs(zisin-hunsin)
sa = min(sa, 360-sa)
sa_pi = sa/180*math.pi

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

print(C)

Solution (Python):
import math

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

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

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

print(ans)

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

le=(a**2+b**2-2*a*b*cosk)**0.5
print(le)

Solution (Python):
from math import cos,radians
from decimal import Decimal
a,b,h,m = map(int,input().split())
x = 6*m
y = Decimal(60*h+m)/2
if x < y: x,y = y,x
z = min(x-y,y+360-x)
print((a**2+b**2-2*a*b*cos(radians(z)))**0.5)

Solution (Python):
import math

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

long_angle=6*m
short_angle=(60*h+m)/2
angle=max(long_angle,short_angle)-min(long_angle,short_angle)
if angle>180:
    angle=360-angle

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

Solution (Python):
import math

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

    hourAngle = math.pi * (h * 30 + m * 0.5) / 180
    minuteAngle = math.pi * (m * 6) / 180

    hourX = a * math.sin(hourAngle)
    hourY = a * math.cos(hourAngle)

    minuteX = b * math.sin(minuteAngle)
    minuteY = b * math.cos(minuteAngle)

    res = ((hourX - minuteX)**2 + (hourY - minuteY)**2)**0.5

    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import math

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

h_just=30*h


hm=h_just-(5.5*m)

if hm<0:
  hm=hm*(-1)

elif hm>180:
  hm=360-hm




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

Solution (Python):

import math




A, B, H, M, = map(int, input().split(' '))
s_needle = 30 * H + 0.5 * M
l_needle = 6 * M

s_x, s_y = math.cos(math.radians(s_needle)) * A, math.sin(math.radians(s_needle)) * A
l_x, l_y = math.cos(math.radians(l_needle)) * B, math.sin(math.radians(l_needle)) * B




l = math.sqrt((s_x - l_x)**2 + (s_y - l_y)**2)
print(l)

Solution (Python):
import math,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
A,B,H,M = LI()
angle = abs((H+M/60)/12*360-M/60*360)
angle = min(angle,360-angle)
print((A**2+B**2-2*A*B*math.cos(math.radians(angle)))**0.5)

Solution (Python):


import sys

import math




























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    a, b, h, m = mi()
    minutes = 60 * h + m
    rad_a = 360 * (minutes / (12 * 60))
    rad_b = 360 * (m / 60)
    print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(abs(rad_a - rad_b)))))



if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
import math

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

Lx = B * math.sin(M / 30 * math.pi)
Ly = B * math.cos(M / 30 * math.pi)
Sx = A * math.sin((H / 6 + M / 360) * math.pi)
Sy = A * math.cos((H / 6 + M / 360) * math.pi)



print(math.sqrt(pow(Sx - Lx, 2) + pow(Sy - Ly, 2)))

Solution (Python):
import math


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


Ax = A * math.cos(math.radians(H * 30 + 0.5 * M))
Ay = A * math.sin(math.radians(H * 30 + 0.5 * M))


Bx = B * math.cos(math.radians(6 * M))
By = B * math.sin(math.radians(6 * M))

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

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import math
def dist(pa,pb):
    return math.sqrt((pa[0]-pb[0])**2+(pa[1]-pb[1])**2)

def theta(h,m):
    return math.pi * (h+m/60.0) / 6.0

def phi(m):
    return math.pi * m / 30.0

def pos(r,th):
    return (r*math.cos(th), r*math.sin(th))

a,b,h,m = inm()
pa = pos(a,theta(h,m))
pb = pos(b,phi(m))
print(dist(pa,pb))

Solution (Python):
import math
a,b,h,m = map(int,input().split())
c = 30*h+0.5*m
d = 6*m
e = c-d
f = math.cos(math.radians(c-d))
z = math.sqrt(a**2+b**2-2*a*b*f)
print(z)

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

q = (m/60)*360

s = (h/12)*360+m*0.5

w = min(abs(s-q),abs(360-(s-q)))
z = a**2+b**2-2*a*b*math.cos(math.radians(w))

print(z**0.5)

Solution (Python):



import math


a, b, h, m = map(int,input().split())
hdeg = 360 * (h / 12 + (m / 60 / 12))
mdeg = 360 * m / 60
deg = abs(hdeg - mdeg)



yog = (a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(deg))) ** (1/2)
ans = yog


print(ans)

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

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

omgA = 2*pi/720
omgB = 2*pi/60
time = 60*H + M

hour = [A*cos(omgA*time), A*sin(omgA*time)]
min = [B*cos(omgB*time), B*sin(omgB*time)]

ans = sqrt(((hour[0] - min[0])**2) + ((hour[1] - min[1])**2))

print(ans)

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

alpha = 60 * h + m
beta = m
base = abs(math.pi * alpha / 360 - math.pi * beta / 30)
th = min(base,2*math.pi - base)

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

Solution (Python):
import math

def calcAngle(h,m): 
          
        
        if (h < 0 or m < 0 or h > 12 or m > 60): 
            print('Wrong input') 
          
        if (h == 12): 
            h = 0
        if (m == 60): 
            m = 0
          
        
        
        
        hour_angle = 0.5 * (h * 60 + m) 
        minute_angle = 6 * m 
          
        
        angle = abs(hour_angle - minute_angle) 
          
        
        
        angle = min(360 - angle, angle) 
          
        return math.radians(angle)
    
A, B, H, M = list(map(int,input().split()))
angle = calcAngle(H,M)
hypotenuse = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(angle))

print('{0:.20f}'.format(hypotenuse))

Solution (Python):


import math

short, long, H, M = map(int, input().split())

x_pos_short = short * math.sin(math.radians(H*30 + (30*(M/60))))
y_pos_short = short * math.cos(math.radians(H*30 + (30*(M/60))))

x_pos_long = long * math.sin(math.radians(M*6))
y_pos_long = long * math.cos(math.radians(M*6))

dist = math.sqrt(math.pow((x_pos_short - x_pos_long),2) + math.pow((y_pos_short - y_pos_long),2))

print(dist)

Solution (Python):
import math

A,B,H,M = map(float, input().split())
p = abs(30*H-5.5*M)
p = min(360-p,p)
p *= (math.pi/180.0)
ans = math.sqrt((A-B*math.cos(p))**2 + (B*math.sin(p))**2)

print(ans)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
ha = H * 30 + M * 0.5
ma = M * 6
angle = abs(ha - ma)
if angle > 180:
    angle = 360 - angle
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())

long = 6.0*M
short = 30.0*H+0.50*M

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

Solution (Python):
import math

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

H_degree = H / 12 + (1 / 12) * (M / 60)
M_degree = M / 60



triangle_degree = abs(H_degree - M_degree)


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

Solution (Python):
import math
def main():
    A, B, H, M = map(int, input().split())
    Th = 360*(H/12) + 30*(M/60)
    Tm = 6*M
    Th = math.radians(Th)
    Tm = math.radians(Tm)

    xh, yh = A*math.sin(Th), A*math.cos(Th)
    xm, ym = B*math.sin(Tm), B*math.cos(Tm)
    d = math.sqrt((xh - xm)**2 + (yh - ym)**2)
    print(d)

if __name__ == "__main__":
    main()

Solution (Python):
import math

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

x = 360//12
y = 360//60

a = M*y
b = (H+M/60)*x
T = 1
if a>=b:
  if a-b>180:
    k = 360 - a+b
  elif a - b == 180:
    print(A+B)
    T = 0
  else:
    k = a-b
else:
  if b-a>180:
    k = 360 - b+a
  elif b-a == 180:
    print(A+B)
    T = 0
  else:
    k = b-a

if T == 1:
  k = math.radians(k)

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

  print(math.sqrt(ans))

Solution (Python):
import sys
import math
def solution():
    a,b,h,m=map(int,input().split())
    mins=m*6
    if(h==12):
        h=0
    hr=h*30+m/2
    angle=min((abs(hr-mins),360-abs(hr-mins)))
    c=a**2+b**2-(2*a*b*math.cos(angle*math.pi/180))
    c=c**(0.5)
    print(c)
if __name__ == "__main__":
    solution()

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

min_total = h*60 + m
rad_h = min_total*0.5 % 360
rad_m = m*6
rad_diff = abs(rad_h - rad_m)
if rad_diff >= 180:
    rad_diff = 360 - rad_diff

result2 = a**2 + b**2 - 2*a*b*cos(radians(rad_diff))
print(sqrt(result2))

Solution (Python):
import math

nums = list(map(lambda x:int(x), input().split()))
a, b, h, m = nums[0], nums[1], nums[2], nums[3]

wa = 0.5
wb = 6

tm = 60 * h + m

da = tm * wa * math.pi / 180
db = (tm % 60) * wb * math.pi / 180
diff = abs(da - db)
csq = a*a + b*b - (2 * a * b * math.cos(diff))
print("{:.20f}".format(math.sqrt(csq)))

Solution (Python):
import math

a, b, h, m = map(int, input().split())
x = h * (360 / 12) + m * (30 / 60)
y = m * (360 / 60)

z = x - y if x >= y else y -x
ans = math.sqrt((a*a) + (b*b) - 2 * a * b * math.cos(math.radians(z)))
print(ans)

Solution (Python):
import numpy as np

def calc(theta, l):
  if theta >= 0 and theta <= np.pi/2:
    return l * np.sin(theta), l * np.cos(theta)
  elif theta > np.pi/2 and theta <= np.pi:
    return l * np.cos(theta - np.pi/2), - l * np.sin(theta - np.pi/2)
  elif theta > np.pi and theta <= np.pi * 1.5:
    return - l * np.sin(theta - np.pi), - l * np.cos(theta - np.pi)
  else:
    return - l * np.cos(theta - np.pi*1.5), l * np.sin(theta - np.pi*1.5)
  

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

theta_m = m * np.pi / 30
theta_h = (h * np.pi / 6) + (m * np.pi / 360)

x1, y1 = calc(theta_h, a)
x2, y2 = calc(theta_m, b)

print(((x1-x2)**2 + (y1-y2)**2)**0.5)