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
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]


def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

a,b,h,m = get_all_int()
theta_h = math.radians(360 * (h/12+m/60/12))
theta_m = math.radians(360 * (m/60))




hx = math.cos(theta_h) * a
hy = math.sin(theta_h) * a
mx = math.cos(theta_m) * b
my = math.sin(theta_m) * b

dx = abs(hx - mx)
dy = abs(hy - my)

print(math.sqrt(dx**2 + dy**2))

Solution (Python):
import math
inp=input("")
li=inp.split()
A=eval(li[0])
B=eval(li[1])

H=eval(li[2])
M=eval(li[3])
angleH=H/6*math.pi+M*math.pi/360
angleM=M*math.pi/30
if(abs(angleH-angleM)>=math.pi):
    angle=2*math.pi-abs(angleH-angleM)
else:
    angle=abs(angleH-angleM)
distance=math.sqrt(pow(A,2)+pow(B,2)-2*A*B*math.cos(angle))
print(distance)

Solution (Python):
import math
a, b, h, m = map(int, input().split())
msita = 6*m
hsita = 30*h + 30*m/60
sita = abs(msita - hsita)
sita = min(sita, 360-sita)
c = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(sita)))
print(c)

Solution (Python):


import math


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


A, B, H, M = LI()


def main():
    t = abs((30 * H + 0.5 * M) - 6 * M)
    if t > 180:
        t = 360 - t
    t = math.radians(t)
    x2 = (A ** 2 + B ** 2) - (2 * A * B * math.cos(t))
    ans = x2 ** 0.5
    print(ans)


if __name__ == "__main__":
    main()

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

Solution (Python):
def resolve():
    import math
    a,b,h,m= map(int, input().split())
    x=h*30-5.5*m
    kaku=math.cos(math.radians(x))
    c=math.sqrt(a**2+b**2-2*a*b*kaku)
    print(c)
resolve()

Solution (Python):
import numpy as np
import math
A, B, H, M = map(int, input().split())
thetaB = 6 * M
thetaA = 0.5 * (60 * H + M)
Ax = math.sin(math.radians(thetaA)) * A
Ay = math.cos(math.radians(thetaA)) * A
Bx = math.sin(math.radians(thetaB)) * B
By = math.cos(math.radians(thetaB)) * B
AA = np.array([Ax,Ay])
BB = np.array([Bx,By])
print(np.linalg.norm(AA-BB))

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

Solution (Python):
import numpy as np

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

k = ((330*h+5.5*m)%360)*np.pi/180

w = np.sqrt(a**2+b**2 - 2*a*b*np.cos(k))

print(w)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


A, B, H, M = getNM()
minu = H * 60 + M
angh = minu / 2
angm = M * 6
anglepre = abs(angh - angm)
angle = min(360 - anglepre, anglepre)
ans = (A ** 2) + (B ** 2) - (2 * A * B * math.cos(math.radians(angle)))
print(math.sqrt(ans))

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

M2 = 12 * M / 60
H2 = H + M/60
theta = abs(H2-M2) / 12 * 360




import math
c = A**2 + B**2 - 2*A*B*math.cos(theta*math.pi/180)
print(c**0.5)

Solution (Python):
import sys
import  math
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A,B,H,M=nm()

time=60*H+M
max_t=60*12
max_h=60

dx=A*math.cos(math.radians(360*time/max_t))-B*math.cos(math.radians(360*M/max_h))
dy=A*math.sin(math.radians(360*time/max_t))-B*math.sin(math.radians(360*M/max_h))

print(math.sqrt(dx*dx+dy*dy))

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

ans = 0
a_a = (h+m/60)/12*2*math.pi
a_b = m/60*2*math.pi

ans = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(abs(a_a-a_b)))
print(ans)

Solution (Python):
import numpy as np
A,B,H,M = map(int,input().split())
def f(th):
    return np.sqrt(A**2+B**2-2*A*B*np.cos(th))
th1 = (1/30)*M*(np.pi)
th2 = (1/6)*H*(np.pi)+(1/360)*M*(np.pi)
theta = abs(th1-th2)
print(f(theta))

Solution (Python):
import sys
import math


def sin(x):
    return math.sin(math.radians(x))


def cos(x):
    return math.cos(math.radians(x))


A, B, H, M = map(int, sys.stdin.readline().strip().split())

Ay = A * sin(90 - (360/12 * H + (360/12)/60 * M))
Ax = A * cos(90 - (360/12 * H + (360/12)/60 * M))
By = B * sin(90 - 360/60 * M)
Bx = B * cos(90 - 360/60 * M)

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

Solution (Python):
from math import sin, cos, radians
A, B, H, M = map(int, input().split())  
hour_hand_theta = (H*60+M)*0.5
minit_hand_theta = 6*M





x1 = A*cos(radians(hour_hand_theta))
y1 = A*sin(radians(hour_hand_theta))


x2 = B*cos(radians(minit_hand_theta))
y2 = B*sin(radians(minit_hand_theta))


ans = ((x1-x2)**2 + (y1-y2)**2) ** (1/2)
print(ans)

Solution (Python):
import math
pi=math.pi
def calcAngle(h,m): 
    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())
angle=calcAngle(H,M)
t= A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(angle))
print("{0:.15f}".format(t**0.5))

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

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

phi_h = -(H*60+M)/(12*60) * 2 * np.pi
phi_m = -(M/60) * 2 * np.pi
distance = np.sqrt(A**2+B**2 - 2*A*B*np.cos(phi_h-phi_m))
print("{:.020f}".format(distance))

Solution (Python):
import math
a, b, h, m = map(int, input().split())
deg_long = (60 * h + m) * 6
deg_short = (60 * h + m) / 2
len_2 = a*a + b*b - 2 * a * b * math.cos(math.radians(deg_long - deg_short))
print(math.sqrt(len_2))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
kakudoA = (H+M/60)*30
kakudoB = M*6
kakudo = min(abs(kakudoA-kakudoB),360-abs(kakudoA-kakudoB))
henn2 = A**2+B**2-2*A*B*math.cos(math.radians(kakudo))
print(henn2**0.5)

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

Solution (Python):
import math

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

short = (h + m/60) * 30
long = m * 6

big = max(short, long)
small = min(short, long)
  
theta = min(big-small, (360-big) + small)

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

Solution (Python):
import math

def main():
    A,B,H,M=map(int, input().split())
    H=(H*60+M)/720*360
    M=M/60*360
    k=abs(H-M)
    ans=(A**2+B**2-2*A*B*math.cos(math.radians(k)))**0.5
    print(ans)
    return

if __name__=='__main__':
    main()

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

Solution (Python):
import sys
import math
from collections import defaultdict,Counter

sys.setrecursionlimit(10**7)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,h,m=mis()
    if m==0:
        arg=min(h*30,360-h*30)
    else:
        H=h*30+m*0.5
        M=m*6
        l=min(abs(H-M),360-abs(H-M))
        arg=min(l,360-l)
    print((a**2+b**2-2*a*b*math.cos(math.radians(arg)))**0.5)
    


if __name__ == "__main__" :
    main()

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, h, m = map(int, input().split())
    t = h * 60 + m
    diff = min((5.5 * t) % 360, 360 - ((5.5 * t) % 360))

    res = pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(diff))
    print(pow(res, 0.5))

if __name__ == '__main__':
    resolve()

Solution (Python):
import math 

a,b,h,m = map(int,input().split())
arg = abs((m/30-((h%12)*60+m)/360)*math.pi)
argcos = math.cos(arg)
print(math.sqrt(a**2 + b**2 - 2*a*b*argcos))

Solution (Python):
import math
a,b,h,m=map(int,input().split())
anga=h*math.pi/6+m*math.pi/360
angb=m*math.pi/30
ax=a*math.cos(anga)
ay=a*math.sin(anga)
bx=b*math.cos(angb)
by=b*math.sin(angb)

l=((ax-bx)**2+(ay-by)**2)**0.5
print(l)

Solution (Python):
import math

a,b,h,m=map(int,input().split())
w=(h/6+m/360)*math.pi
z=(m/30)*math.pi
l=(a*math.sin(w)-b*math.sin(z))**2+(a*math.cos(w)-b*math.cos(z))**2
print(l**(1/2))

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

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


import math

a_rad = math.radians((h+m/60)/12 * 360)

b_rad = math.radians(m/60 * 360)

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

Solution (Python):
import math

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

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

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

print(math.sqrt(length2))

Solution (Python):

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


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


def II():
    return int(input())

A,B,H,M=acinput()



theta2=2*np.pi*(M/60)
H+=(M/60)
theta1=(H%12)*2*np.pi*(30/360)

print(np.sqrt(A**2+B**2-2*A*B*np.cos(np.abs(theta1-theta2))))

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

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

edge = max(30*H+0.5*M,6*M) - min(30*H+0.5*M,6*M)
C = math.cos(math.radians(edge))
ans = math.sqrt(pow(A,2) + pow(B,2) - 2 * A * B * C)
print(ans)

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

mi = M/60
ti = (H*60+M)/720

angle = abs(mi-ti)*math.pi*2

c_2 = A**2+B**2-2*A*B*math.cos(angle)

print(math.sqrt(c_2))

Solution (Python):
import math

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

theta = math.radians(abs(30 * H + 0.5 * M - 6 * M))


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



print(ans)

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

def calculate(a, b, h, m):
    hradians = ((h % 12) / 12)*360 + (((m/60) % 12) / 12)*360
    mradians = (m / 60) * 360

    hx = a * math.sin(math.radians(hradians))
    hy = a * math.cos(math.radians(hradians))

    mx = b * math.sin(math.radians(mradians))
    my = b * math.cos(math.radians(mradians))

    print(distance(hx,hy,mx,my))

def distance(x1,y1,x2,y2):
    return math.sqrt(abs(x1-x2)**2 + abs(y1-y2)**2)
calculate(A, B, H, M)

Solution (Python):
import math
A, B, H, M = list(map(int, input().split()))
h_theta = H / 12 * 2.0 * math.pi + M / 60 / 12 * 2.0 * math.pi
m_theta = M / 60 * 2.0 * math.pi
theta = abs(h_theta - m_theta)
L = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta))
print(L)

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

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


h = h + (m/60)

longAngle = 360 * (h/12)
shortAngle = 360 * (m/60)

angle = abs(longAngle-shortAngle)

if angle > 180:
    angle = 360 - angle


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

print(sqrt(ans))

Solution (Python):
import math


def main():
    A, B, H, M = [int(v) for v in input().split()]

    h = H + M / 60.0

    rad_a = math.pi * h / 6.0
    ay = A * math.sin(rad_a)
    ax = A * math.cos(rad_a)

    rad_b = math.pi * M / 30.0
    by = B * math.sin(rad_b)
    bx = B * math.cos(rad_b)

    dx = ax - bx
    dy = ay - by

    l = math.sqrt(dx * dx + dy * dy)
    print(l)


main()

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

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

h = float(h)
m = float(m)
ra = 30*h+0.5*m
rb = 6*m
diff = ra - rb

if diff > 180:
   diff = 360 - diff

import math

c2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(diff))
print(c2**0.5)

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

hun = H*60+M

angleB = 360*(hun%60) / 60
angleA = 360*(hun/720)

if( angleB > angleA ):
    diff = angleB - angleA
else:
    diff = angleA - angleB

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


c = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.pi*diff/180))

print(c)

Solution (Python):
import math

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

hour = h * (360 / 12) + m * (1/2)
mini = m * (360 / 60)
dig = hour - mini
dig = dig if dig < 180 else 360 - dig


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

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

import math

v_h = (2*math.pi) / (12*60)
v_m = (2*math.pi) / 60

length = math.sqrt(A**2 + B**2 -2*A*B*math.cos(v_h*(H*60+M)-v_m*M))
print(length)

Solution (Python):
import math

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

x = (H + M / 60) / 12 * 360
y = M / 60 * 360

if x < y:
    x, y = y, x

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

Solution (Python):

import math

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

if 30*h > 5.5*m:
    theta = 30*h-5.5*m
else:
    theta = -(30*h-5.5*m)

if theta >= 180:
    theta = 360-theta


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

Solution (Python):



import math

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

deg = (H + M / 60) * 30 - M / 60 * 360

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

print (l)

Solution (Python):
A,B,H,M=map(int,input().split())
from math import cos
p=3.14159265358979323846264338328
ho=H*p/6+M*p/360
mi=M*p/30
t=ho-mi
x=(A*A+B*B-2*A*B*cos(t))**0.5
print(x)

Solution (Python):
import math


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

    ang_a = (360 * h / 12 + 360 * m / 12 / 60) % 360
    ang_b = 360 * m / 60 % 360
    ang = max(ang_a, ang_b) - min(ang_a, ang_b)
    ang = math.radians(min(360 - ang, ang))

    ans = (a ** 2 + b ** 2 - 2 * a * b * math.cos(ang)) ** 0.5
    return ans


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

Solution (Python):
import math

a,b,h,m=map(int,input().split())
if(5*(h+m/60)<=m):
    s=m-5*(h+m/60)
else:
    s=5*(h+m/60)-m
cc=a*a+b*b-2*a*b*math.cos(s/60*2*math.pi)
c=cc**0.5
print(c)

Solution (Python):
import numpy as np
a,b,h,m=map(int,input().split())
s=abs(6*m-30*(h+m/60))
t=min(s,360-s)
t=np.deg2rad(t)
c=(a**2+b**2-2*a*b*np.cos(t))**(1/2)
print(c)

Solution (Python):
import math

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

s = abs(float(6*M - 30*(H + M/60)))

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

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

theta_a = (h/12+m/60/12)*2*pi
theta_delta = abs(theta_a - m/30*pi)
ans = math.sqrt(a**2 + b**2 - 2.0*a*b*math.cos(theta_delta))
print(ans)

Solution (Python):
import math

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

theta_long = 360 / (60 * 12) * (60 * H + M)
theta_short = 360 / 60 * M
theta = abs(theta_long - theta_short) * math.pi / 180
print((A**2 + B**2 - 2 * A * B * math.cos(theta))**0.5)

Solution (Python):
import math

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

d = abs((360 * (H * 60 + M) / 720) - (360 * M / 60))

d = min(d, abs(360 - d))

C2 = A * A + B * B - 2 * A * B * math.cos(math.radians(d))

print(C2 ** (1 / 2))

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

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

posA = 30 * H + 0.5 * M
posB = 6 * M

if posA - posB < 180:
    theta = posA - posB
else:
    theta = 360 - (posA - posB)

res = sqrt(A * A + B * B - 2 * A * B * cos(radians(theta)))

print(res)

Solution (Python):
import math
A,B,H,N= map(int,input().split())
sa=((15-H)%12)*30-N/2
sb=((75-N)%60)*6
c1=math.sin(math.radians(sa))*A
c2=math.cos(math.radians(sa))*A
d1=math.sin(math.radians(sb))*B
d2=math.cos(math.radians(sb))*B
print(((c1-d1)**2+(c2-d2)**2)**(0.5))

Solution (Python):
import math

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

a = 360 * (H/12 + 1/12*M/60)
b = 360 * M/60

c = abs(a-b)
c = min(c,360-c)
cos = math.cos(math.radians(c))

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

print(hypotenuse)

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

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

Solution (Python):
import math


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


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

h=30*H
h+=6*(M/12)
if h==0:
    h=360

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

Solution (Python):
import math
A,B,H,M=list(map(int,input().split()))
argH=30*H+(30/60)*M
argM=6*M
sita=math.radians(min(abs(argH-argM),abs(argH-argM)))
ans=math.sqrt(A**2+B**2-2*A*B*(math.cos(sita)))
print(ans)

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

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

chosin = 360*M/60

kakudo = abs(tansin - chosin)
kotae = A**2 + B**2 - 2*A*B*(math.cos(math.radians(kakudo)))

print(math.sqrt(kotae))

Solution (Python):
import math
A, B, H, M = list(map(float,input().split()))
rad = 6*(60*H+M)-0.5*(60*H+M)
while(rad > 180):
	if rad > 360:
		rad -= 360
	else:
		rad = 360 - rad
r = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(rad*math.pi/180))
print(r)

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

M_deg = M * 6
H_deg = H * 30 + M * 0.5
angle = abs(M_deg-H_deg)

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

ans =math.sqrt(( A*A) + (B*B) - (2*A*B*cos_angle))

print(ans)

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

import math

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

btheta = M / 60 * 2 * math.pi

theta = abs(atheta - btheta)
if theta >= math.pi:
  theta = 2*math.pi - theta


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

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

kakua = 30 * h + 0.5 * m
kakub = 6 * m
soutai = min((abs(kakua - kakub), 360 - abs(kakua - kakub)))

print(abs(a ** 2 + b ** 2 - 2*a*b*(math.cos(math.pi/180*soutai)))**(1/2))

Solution (Python):
import math

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

X = (A*math.cos(math.pi*M/30)-B*math.cos((math.pi/6)*(H+M/60)))**2
Y = (A*math.sin(math.pi*M/30)-B*math.sin((math.pi/6)*(H+M/60)))**2

print(math.sqrt(X+Y))

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

Solution (Python):

import math

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

th = abs((h/12 + m/60/12) * 2 * math.pi - m/60 * 2 * math.pi)
if th <= 180:
    c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th))
else:
    th = th - 180
    c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th))
    
print(c)

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

m1 = 360*m/60
h1 = 360*(h+m/60)/12
bun = abs(m1-h1)
if bun>180:
    bun = abs(bun-360)
import math
if bun==180:
    print(a+b)
elif bun==0:
    print(abs(a-b))
else:
    ans = math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(bun)))
    print(ans)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
a=360*H/12+360*M/60/12
b=360*M/60
c=abs(a-b)
if c>180:
    c=360-c
C=(A**2+B**2-(2*A*B*math.cos(math.radians(c))))**0.5
print(C)

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

angle=(h/12.0)*2*math.pi+(m/60)/12.0*2*math.pi-(m/60.0)*2*math.pi
c2=a**2+b**2-2*a*b*math.cos(angle)
answer=c2**(0.5)
print(answer)

Solution (Python):
import math

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

print(math.sqrt(A**2+B**2-2*A*B*math.cos(abs((2*math.pi/12*H+math.pi/360*M)-(2*math.pi/60*M)))))

Solution (Python):
import math

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

n = h*60 + m
p = math.pi

xa = a * math.sin(n*2*p/720)
ya = a * math.cos(n*2*p/720)

xb = b * math.sin(m*2*p/60)
yb = b * math.cos(m*2*p/60)

l = ((xa-xb)**2+(ya-yb)**2)**(1/2)

print(l)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
m = 60 * H + M
h_rad = m / 360
m_rad = M / 30
dif = 1 - abs(abs(h_rad - m_rad) - 1)
C = math.sqrt(A * A + B * B - 2 * A * B * math.cos(dif * math.pi))
print(C)

Solution (Python):
import math

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


x = 30 * h + 0.5 * m

y = 6 * m

dif = max(x-y, y-x)
if dif > 180:
    theta = math.radians(360 - dif)
else:
    theta = math.radians(dif)

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

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

import math

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

k=min(abs(h-m),360-abs(h-m))

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

print(math.sqrt(ans))

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

theta_h=M/30*math.pi
theta_m=(H/6+M/360)*math.pi


ans=A**2+B**2-2*A*B*(math.sin(theta_h)*math.sin(theta_m)+math.cos(theta_h)*math.cos(theta_m) )
print(ans**(1/2))

Solution (Python):
import sys
from math import sqrt, cos, radians
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


A, B, H, M = MI()

d1 = (H * 60 + M) / 720
d2 = M / 60
theta = 360 * min(abs(d1 - d2), 1 - abs(d1 - d2))
ans = sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(radians(theta)))
print(ans)

Solution (Python):
import math
A,B,H,M = map(int,input().split())
 
A_deg = 360*H/12 + 360*M/(60*12)
B_deg = 360*M/60
C_deg = A_deg-B_deg
if C_deg < 0:
    C_deg = -C_deg 
if C_deg > 180:
    C_deg = 360 - C_deg
    
C = (A**2+B**2-2*A*B*math.cos(math.radians(C_deg)))**(1/2)
print(C)

Solution (Python):

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


short = h * (360 / 12) + m * 0.5
lon = m * 6
angle = abs(lon - short)
angle = min(angle, 360 - angle)
ans = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(angle))
print(ans ** 0.5)

Solution (Python):
import math

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

h_d = 30*h + 30 * (m/60)
m_d = 360 * (m/60)

diff = abs(h_d-m_d)
c_2 = (a**2) + (b**2) - 2*a*b*math.cos(math.radians(diff))

print(math.sqrt(c_2))

Solution (Python):
def main():
    import numpy as np
    a, b, h, m = map(int, input().split())
    x = h + m / 60
    p = x % 12
    s, t = p / 12 * 360, m / 60 * 360

    d = min(t + 360 - s, abs(s-t))
    ans = a ** 2 + b ** 2 - 2 * a * b * np.cos(np.pi * d / 180)
    print(ans ** 0.5)


if __name__ == '__main__':
    main()

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

Hc=math.cos(math.radians(H*60+M)/2)
Hs=math.sin(math.radians(H*60+M)/2)
Mc=math.cos(math.radians(M*6))
Ms=math.sin(math.radians(M*6))

            
P=((Hc*A-Mc*B)**2+(Hs*A-Ms*B)**2)**0.5
print(P)

Solution (Python):
import math
A, B, H, M = map(int, input().split())
s = 0.5 * (H*60+M)
l = 6 * M
c = max(s, l) - min(s, l)

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

Solution (Python):
import math
A,B,H,M = map(int,input().split())
x = abs(30*H +0.5*M -6*M)
c = min(x,360-x)
ans = (A ** 2) + (B ** 2)  - (2 * A * B * math.cos(math.radians(c)))

ans = math.sqrt(ans)
print(ans)

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

min=h*60+m
place_a=math.radians(min*0.5)
place_b=math.radians(min*6%360)

ans = math.sqrt((b*math.cos(place_b)-a*math.cos(place_a))**2 +
                (b*math.sin(place_b)-a*math.sin(place_a))**2)
print(ans)

Solution (Python):
import math
short, lon, hour, minute = map(int, input().split()) 
time = hour * 60 + minute
lon_angle = minute * 6
short_angle = time * 0.5
angle = abs(lon_angle - short_angle)
angle = math.radians(angle)
ans = short**2 + lon**2 -2*short*lon*math.cos(angle)
print(math.sqrt(ans))

Solution (Python):
import math
A,B,H,M =map(int,input().split())
ans = 0
kaku = 30 * H -5.5 * M
if abs(kaku) > 180:
    kaku = 360-abs(kaku)
ans = math.sqrt(A**2 + B**2 -2*A*B*math.cos(math.radians(abs(kaku))))
print(ans)

Solution (Python):
import math
a,b,h,m = map(int,input().split())
w_zi = 2*math.pi/(12*60)
w_hun = 2*math.pi/60
zi_x = a*math.cos(-w_zi*(h*60+m))
zi_y = a*math.sin(-w_zi*(h*60+m))
hun_x = b*math.cos(-w_hun*(h*60+m))
hun_y = b*math.sin(-w_hun*(h*60+m))

ans = math.sqrt((zi_x - hun_x)**2 + (zi_y - hun_y)**2)
print(ans)

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

Solution (Python):
import math

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

Atheta = H * 30 + 0.5*M
Btheta = M * 6

theta = min(abs(Atheta - Btheta), abs(360 - (Atheta - Btheta)))

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

Solution (Python):
import math

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

degree_minute = 360 * m/60
degree_hour = 360 * h / 12 + 30 * m/60

angle = abs(degree_minute - degree_hour)
if angle > 180:
    angle = 360 - angle

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

print(distance)

Solution (Python):
import math

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

m = H*60+M

ch = math.radians(m*360/720)
hx, hy = A*math.cos(ch), A*math.sin(ch)
cm = math.radians(M*6)
mx, my = B*math.cos(cm), B*math.sin(cm)

ans = pow(pow(hx-mx, 2) + pow(hy-my, 2), 0.5)
print(ans)

Solution (Python):
import math

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

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

d=min(s,360-s)

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

print(math.sqrt(c))

Solution (Python):
import math

a, b, h, m = map(float, input().split())
da = 0
db = 0

db = float(6) * m
da = float(30) * h + m / float(2)

sa = abs(da - db)
if sa >= float(180):
    sa = float(360) - sa

rad = math.cos(math.radians(sa))

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

Solution (Python):
import sys
import math


def input():
    return sys.stdin.readline()[:-1]

A, B, H, M = map(int, input().split())
rad_H = math.pi*2 * H / 12 + math.pi/6 * M / 60
rad_M = math.pi*2 * M / 60

diff_rad = abs(rad_H-rad_M)
if diff_rad > math.pi:
	diff_rad = 2*math.pi - diff_rad


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

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

HtoM = (H * 5) % 60

Mdeg = M * 6
Hdeg = (H * 30 + M * 0.5) % 360



deg = abs(Mdeg - Hdeg)
deg = min(abs(360 - deg), deg)


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

Solution (Python):
import math
a,b,h,m = map(int,input().split())
hthta = 30*h+0.5*m
mthta = 6*m

thta = abs(hthta-mthta)
if thta > 180:
    thta = 360-thta

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

Solution (Python):
import math

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

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

vh=[A*math.cos(theta_h), A*math.sin(theta_h)]
vm=[B*math.cos(theta_m), B*math.sin(theta_m)]
print(math.sqrt((vh[0]-vm[0])**2+(vh[1]-vm[1])**2))

Solution (Python):
import math

data = input().split()
data = [int(i) for i in data]

short_x = data[0] * math.cos(math.radians(360 * (60 * data[2] + data[3]) /720))
short_y = data[0] * math.sin(math.radians(360 * (60 * data[2] + data[3]) /720))

long_x = data[1] * math.cos(math.radians(360 * (data[3]) / 60))
long_y = data[1] * math.sin(math.radians(360 * (data[3]) / 60))

print( math.sqrt((short_x - long_x) * (short_x - long_x) + (short_y - long_y) * (short_y - long_y)))

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

Solution (Python):


def solve():
    import sys
    import math

    A, B, H, M = list(map(int, sys.stdin.readline().split()))

    h_speed = 360 / (12*60)
    m_speed = 360 / 60

    m = H*60 + M

    h_angle = h_speed * m
    m_angle = m_speed * m % 360
    angle = abs(h_angle - m_angle) if abs(h_angle-m_angle) <= 180 else 360 - abs(h_angle-m_angle)

    if angle == 0:
        print(abs(A-B))
        return
    elif angle == 180:
        print(A+B)
        return

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

if __name__ == "__main__":
    solve()

Solution (Python):
import math
a,b,h,m=map(int,input().split())
s=0.5*(h*60+m)
l=6*m
rad=max(s,l)-min(s,l)
if rad>180:
    rad=360-rad
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())

long = 360*m/60
short = 360*h/12 + 30*m/60
deg = min(abs(long-short), 360-abs(long-short))

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

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

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

short = (minutes / (12 * 60)) * 360
long = ((minutes / 60) % 60) * 360
if short >= long:
    arg = short - long
else:
    arg = long - short

a = (A ** 2) + (B ** 2) - (2 * A * B * cos(radians(arg)))
print(sqrt(a))