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 os

import cmath
import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7





class Point:
    """
    2次元空間上の点
    """

    
    CCW_COUNTER_CLOCKWISE = 1
    
    CCW_CLOCKWISE = -1
    
    CCW_ONLINE_BACK = 2
    
    CCW_ONLINE_FRONT = -2
    
    CCW_ON_SEGMENT = 0

    def __init__(self, x: float, y: float):
        self.c = complex(x, y)

    @property
    def x(self):
        return self.c.real

    @property
    def y(self):
        return self.c.imag

    @staticmethod
    def from_complex(c: complex):
        return Point(c.real, c.imag)

    @staticmethod
    def from_polar(r: float, phi: float):
        c = cmath.rect(r, phi)
        return Point(c.real, c.imag)

    def __add__(self, p):
        """
        :param Point p:
        """
        c = self.c + p.c
        return Point(c.real, c.imag)

    def __iadd__(self, p):
        """
        :param Point p:
        """
        self.c += p.c
        return self

    def __sub__(self, p):
        """
        :param Point p:
        """
        c = self.c - p.c
        return Point(c.real, c.imag)

    def __isub__(self, p):
        """
        :param Point p:
        """
        self.c -= p.c
        return self

    def __mul__(self, f: float):
        c = self.c * f
        return Point(c.real, c.imag)

    def __imul__(self, f: float):
        self.c *= f
        return self

    def __truediv__(self, f: float):
        c = self.c / f
        return Point(c.real, c.imag)

    def __itruediv__(self, f: float):
        self.c /= f
        return self

    def __repr__(self):
        return "({}, {})".format(round(self.x, 10), round(self.y, 10))

    def __neg__(self):
        c = -self.c
        return Point(c.real, c.imag)

    def __eq__(self, p):
        return abs(self.c - p.c) < EPS

    def __abs__(self):
        return abs(self.c)

    
    def __lt__(self, p):
        return self.x - p.x < -EPS or self.x - p.x < EPS and self.y - p.y < -EPS

    def __le__(self, p):
        return self.x - p.x < -EPS or self.x - p.x < EPS and self.y - p.y < EPS

    def __gt__(self, p):
        return self.x - p.x > EPS or self.x - p.x > -EPS and self.y - p.y > EPS

    def __ge__(self, p):
        return self.x - p.x > EPS or self.x - p.x > -EPS and self.y - p.y > -EPS

    @staticmethod
    def ccw(a, b, c):
        """
        線分 ab に対する c の位置
        線分上にあるか判定するだけなら on_segment とかのが速い
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
        :param Point a:
        :param Point b:
        :param Point c:
        """
        b = b - a
        c = c - a
        det = b.det(c)
        if det > EPS:
            return Point.CCW_COUNTER_CLOCKWISE
        if det < -EPS:
            return Point.CCW_CLOCKWISE
        if b.dot(c) < -EPS:
            return Point.CCW_ONLINE_BACK
        if b.dot(b - c) < -EPS:
            return Point.CCW_ONLINE_FRONT
        return Point.CCW_ON_SEGMENT

    def dot(self, p):
        """
        内積
        :param Point p:
        :rtype: float
        """
        return self.x * p.x + self.y * p.y

    def det(self, p):
        """
        外積
        :param Point p:
        :rtype: float
        """
        return self.x * p.y - self.y * p.x

    def dist(self, p):
        """
        距離
        :param Point p:
        :rtype: float
        """
        return abs(self.c - p.c)

    def norm(self):
        """
        原点からの距離
        :rtype: float
        """
        return abs(self.c)

    def phase(self):
        """
        原点からの角度
        :rtype: float
        """
        return cmath.phase(self.c)

    def angle(self, p, q):
        """
        p に向いてる状態から q まで反時計回りに回転するときの角度
        -pi <= ret <= pi
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c) + PI) % TAU - PI

    def area(self, p, q):
        """
        p, q となす三角形の面積
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return abs((p - self).det(q - self) / 2)

    def rotate(self, theta):
        """
        反時計回りに theta だけ回転させた Point を返す
        :param float theta:
        """
        return Point.from_complex(self.c * cmath.rect(1, theta))

    def projection_point(self, p, q, allow_outer=False):
        """
        線分 pq を通る直線上に垂線をおろしたときの足の座標
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=ja
        :param Point p:
        :param Point q:
        :param allow_outer: 答えが線分の間になくても OK
        :rtype: Point|None
        """
        diff_q = q - p
        
        r = (self - p).dot(diff_q) / abs(diff_q)
        
        phase = diff_q.phase()

        ret = Point.from_polar(r, phase) + p
        if allow_outer or (p - ret).dot(q - ret) < EPS:
            return ret
        return None

    def reflection_point(self, p, q):
        """
        直線 pq を挟んで反対にある点
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&lang=ja
        :param Point p:
        :param Point q:
        :rtype: Point
        """
        
        r = abs(self - p)
        
        angle = p.angle(q, self)
        
        angle = (q - p).phase() - angle
        return Point.from_polar(r, angle) + p

    def on_segment(self, p, q, allow_side=True):
        """
        点が線分 pq の上に乗っているか
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
        :param Point p:
        :param Point q:
        :param allow_side: 端っこでギリギリ触れているのを許容するか
        :rtype: bool
        """
        if not allow_side and (self == p or self == q):
            return False
        
        
        return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS

    @staticmethod
    def circumcenter_of(p1, p2, p3):
        """
        外心
        :param Point p1:
        :param Point p2:
        :param Point p3:
        :rtype: Point|None
        """
        if abs((p2 - p1).det(p3 - p1)) < EPS:
            
            return None
        
        a = (p2.x - p3.x) ** 2 + (p2.y - p3.y) ** 2
        b = (p3.x - p1.x) ** 2 + (p3.y - p1.y) ** 2
        c = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2
        num = p1 * a * (b + c - a) + p2 * b * (c + a - b) + p3 * c * (a + b - c)
        den = a * (b + c - a) + b * (c + a - b) + c * (a + b - c)
        return num / den

    @staticmethod
    def incenter_of(p1, p2, p3):
        """
        内心
        :param Point p1:
        :param Point p2:
        :param Point p3:
        """
        
        d1 = p2.dist(p3)
        d2 = p3.dist(p1)
        d3 = p1.dist(p2)
        return (p1 * d1 + p2 * d2 + p3 * d3) / (d1 + d2 + d3)


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

h = Point(0, A).rotate(-(H / 12 + M / 60 / 12) * math.pi * 2)
m = Point(0, B).rotate(-(M / 60) * math.pi * 2)
print(h.dist(m))

Solution (Python):
import numpy as np
a,b,h,m=map(int, input().split())
min = h*60 + m

rada = np.radians(90-min*0.5)
acos = np.cos(rada)
x1 = a * acos
asin = np.sin(rada)
y1 = a * asin

radb = np.radians(90-m*6)
bcos = np.cos(radb)
x2 = b * bcos
bsin = np.sin(radb)
y2 = b * bsin

A = np.array([x1, y1])
B = np.array([x2, y2])
u = B-A
print(np.linalg.norm(u))

Solution (Python):
import math
A,B,H,M = map(int,input().split())
a = 30*H + 0.5*M
b = M*6
if abs(a-b) < 180:
    ab = abs(a-b)
else:
    ab = 360 - abs(a-b)
ab1 = round(math.cos(math.radians(ab)),20)
ans = round(math.sqrt(A**2 + B**2 - 2 * A* B*ab1),20)
print(round(ans,20))

Solution (Python):
import sys
import math

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

AX = 30.0 * H + M / 2.0
BX = M * 6.0

D = AX - BX

ANS = A ** 2 + B ** 2 - 2 * B * A * math.cos(math.radians(D))

print(math.sqrt(ANS))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
H_rad = ((H*30) + 0.5*M) % 360
M_rad = M*6 % 360
kari_kakudo = max(H_rad,M_rad) - min(H_rad,M_rad)
kakudo = math.radians(min(kari_kakudo,360-kari_kakudo))
ans = (pow(A,2)+pow(B,2))-2 * A * B * (math.cos(kakudo))
print(math.sqrt(ans))

Solution (Python):
import numpy as np
s=list(map(int, input().split()))
a =s[0]
b =s[1]
h =s[2]
m=s[3]
min = h*60 + m

rada = np.radians(90-min*0.5)
acos = np.cos(rada)
x1 = a * acos
asin = np.sin(rada)
y1 = a * asin

radb = np.radians(90-m*6)
bcos = np.cos(radb)
x2 = b * bcos
bsin = np.sin(radb)
y2 = b * bsin

A = np.array([x1, y1])
B = np.array([x2, y2])
u = B-A
np.linalg.norm(u)
print(np.linalg.norm(u))

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

d=abs(30*h+0.5*m - 6*m)
d=min(d,360-d)

e=math.cos(math.radians(d))

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

Solution (Python):
import math


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


h_t = (h + m / 60) * (360 / 12)
m_t = m * (360 / 60)

t = abs(h_t - m_t)
print(
    math.sqrt((float(a**2 + b**2)) - (float(2*a*b*math.cos(math.radians(t)))))
)

Solution (Python):
import math

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

short_v = 360 / (12*60)
long_v = 360 / 60

short_arg = (short_v * (H * 60) + short_v * M)
long_arg = long_v * M

tmp = abs(short_arg-long_arg)
if tmp > 180:
    tmp = 360 - tmp
theta = math.radians(tmp)

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

print(math.sqrt(result_2))

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


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

mx = math.cos(mrad) * b
my = math.sin(mrad) * b
hx = math.cos(hrad) * a
hy = math.sin(hrad) * a

d = ((hx - mx) ** 2 + (hy - my) ** 2) ** 0.5
print(d)

Solution (Python):
import math
A,B,H,M=map(int,input().split())
h1=H*30+(M/60)*30
C=min(abs(((H+(M/60))*30)-M*6),abs(abs(((H+(M/60))*30)-M*6)-360))

ansr=A**2+B**2-(2*A*B*round(math.cos(math.radians(C)),10**9))
print(ansr**0.5)

Solution (Python):
from math import cos, pi, sqrt
A, B, H, M = map(int, input().split())
theta = abs(((H + M / 60) % 12) / 6 - (M % 60) / 30) * pi
print(sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(min(360 - theta, theta))))

Solution (Python):



import math

def main():
    A, B, H, M = map(int, input().split())
    rda = math.radians(360*(60*H+M)/(60*12))
    rdb = math.radians(360*M/60)
    La = [A*math.cos(rda),A*math.sin(rda)]
    Lb = [B*math.cos(rdb),B*math.sin(rdb)]
    ret = (La[0]-Lb[0])**2 + (La[1]-Lb[1])**2
    ret = ret ** 0.5
    print(ret)

if __name__ == '__main__':
    main()

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

kaku1 = 360 *minu / (12*60)
kaku2 = 360 *minu / 60
kaku = max(kaku1-kaku2,kaku2-kaku1)

import math

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

Solution (Python):
import math

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

short_v = 360 / (12*60)
long_v = 360 / 60

short_arg = (short_v * (H * 60) + short_v * M)
long_arg = long_v * M

theta = math.radians(abs(short_arg-long_arg))

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

print(math.sqrt(result_2))

Solution (Python):
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(kakudo*math.pi/180)
    
    
    print(math.sqrt(ans))
if __name__ == "__main__":
    main()

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

kaku1 = 360 *minu / (12*60)
kaku2 = 360 *minu / 60
kaku = abs(kaku1-kaku2)

import math

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

Solution (Python):
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(kakudo*math.pi/180)
    print(ans**0.5)
    
    
if __name__ == "__main__":
    main()

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

    theta = (60 * H - 11 * M) * pi / 360
    return sqrt(A**2 + B**2 - 2 * A * B * cos(theta))

print(c_colon())

Solution (Python):
import math
import numpy
a,b,h,m = map(int,input().split())
h = (h*60+m)/2
m = m * 6
hour = numpy.array([math.sin(math.radians(h))*a, math.cos(math.radians(h))*a])


minute = numpy.array([math.sin(math.radians(m))*b, math.cos(math.radians(m))*b])

ans = (hour - minute)
print(numpy.linalg.norm(ans))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
angle = 6 * ((H * 5) - M) + 0.5 * M
res = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(angle)))
print(format(res, '0<11'))

Solution (Python):
import math

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

pi=math.pi

r1=2.0*pi/12.0*h+pi/6.0/60.0*m

r2=2.0*pi/60.0*m

g=a*a+b*b-2.0*a*b*math.cos(r1-r2)

print(math.sqrt(g))

Solution (Python):
import math

INF = 10 ** 9
A,B,H,M = map(int,input().split())

rad_H = (360*H//12) + (0.5 * M)
rad_M = 360*M//60
diff = abs(rad_H-rad_M)




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

print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
d=abs((h*60+m)/2-m*6)
d=min(d,360-d)

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

Solution (Python):
import math
 
def calculate_length(A,B,theta):
    radian=math.radians(theta)
    length=(A**2)+(B**2)-(2*A*B*math.cos(radian))
    return  math.sqrt(length)

def main():
    A,B,H,M = map(int,input().split())
    thetaA=H*30+M*0.5
    thetaB=M*6
    if thetaA == thetaB:
        print(abs(A-B))
    else:
        if thetaA > thetaB:
            theta=thetaA-thetaB
        elif thetaA < thetaB:
            theta = thetaB-thetaA
        length=calculate_length(A,B,theta)
        print(length)

if __name__=="__main__":
    main()

Solution (Python):
A,B,H,M = map(int,input().split())
minute = H * 60 + M
k1 = 360*minute/(12*60)
k2 = 360*minute/ 60
import math
c = math.cos(math.radians(max(k1-k2,k2-k1)))
print((A*A+B*B-2*A*B*c)**(1/2))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
Mkaku = 6 * M
Hkaku = (H * 60 + M) / 2
r1 = Hkaku * math.pi / 180
r2 = Mkaku * math.pi / 180
v1x = A * math.cos(r1)
v1y = A * math.sin(r1)
v2x = B * math.cos(r2)
v2y = B * math.sin(r2)
ans = ((v1x - v2x) ** 2 + (v1y - v2y) ** 2) ** (1 / 2)
print(ans)

Solution (Python):
import math
def main():
    a,b,h,m = map(int, input().split())
 
    ar = h * 360 / 12 + m * 30 / 60
    br = m * 360 / 60
    kakudo = x if (x := abs(ar-br)) < 180 else 360-x
    ans = a**2+b**2-2*a*b*math.cos(math.radians(kakudo))
    print(ans**0.5)
if __name__ == "__main__":
    main()

Solution (Python):
import sys
import math



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


cA = 360*H/12 +30 * M/60
cB = 360*M/60
cC = abs(cA -cB)
if cC > 180:
    cC = 360 - cC


coscC = math.cos(math.radians(cC))
C = A**2 +B**2 - 2* A*B*coscC



print(C**(1/2))

Solution (Python):
import math

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

dighour:float = 30*H + M*0.5
digmin:float =  M * 6
length:float = 0

deg = abs(dighour-digmin)
length = math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(deg))))

'''
if dighour > digmin and abs(dighour - digmin) <= 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians(abs(dighour-digmin)))))
elif dighour > digmin and abs(dighour - digmin) > 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians(360 - abs(dighour-digmin)))))
elif dighour < digmin and abs(digmin - dighour) <= 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians((abs(digmin-dighour))))))
elif dighour < digmin and abs(digmin - dighour) > 180:
    length = math.sqrt((A **2 + B **2) - ((2*A*B) * math.cos(math.radians((360 - abs(digmin-dighour))))))
'''

print(length)

Solution (Python):
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
A,B,H,M=map(int,input().split())

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


print(((A*math.sin(ap)-B*math.sin(bp))**2+(A*math.cos(ap)-B*math.cos(bp))**2)**.5)

Solution (Python):
import math
import numpy as np

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

rad = math.pi*2*(h/12 + m/60/12 - m/60)

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

Solution (Python):

from math import cos,pi,pow
A,B,H,M=map(float,input().split())
 
A_d=pi*(H*60+M)/360
B_d=pi*M/30
D=abs(A_d-B_d)
 
result=pow(A**2+B**2-2*A*B*cos(D),0.5)
print(result)

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

Solution (Python):

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

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

theta = min(th, 360 - th)

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

Solution (Python):
import os

import cmath
import math
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7





class Point:
    """
    2次元空間上の点
    """

    
    CCW_COUNTER_CLOCKWISE = 1
    
    CCW_CLOCKWISE = -1
    
    CCW_ONLINE_BACK = 2
    
    CCW_ONLINE_FRONT = -2
    
    CCW_ON_SEGMENT = 0

    def __init__(self, x: float, y: float):
        self.c = complex(x, y)

    @property
    def x(self):
        return self.c.real

    @property
    def y(self):
        return self.c.imag

    @staticmethod
    def from_complex(c: complex):
        return Point(c.real, c.imag)

    @staticmethod
    def from_polar(r: float, phi: float):
        c = cmath.rect(r, phi)
        return Point(c.real, c.imag)

    def __add__(self, p):
        """
        :param Point p:
        """
        c = self.c + p.c
        return Point(c.real, c.imag)

    def __iadd__(self, p):
        """
        :param Point p:
        """
        self.c += p.c
        return self

    def __sub__(self, p):
        """
        :param Point p:
        """
        c = self.c - p.c
        return Point(c.real, c.imag)

    def __isub__(self, p):
        """
        :param Point p:
        """
        self.c -= p.c
        return self

    def __mul__(self, f: float):
        c = self.c * f
        return Point(c.real, c.imag)

    def __imul__(self, f: float):
        self.c *= f
        return self

    def __truediv__(self, f: float):
        c = self.c / f
        return Point(c.real, c.imag)

    def __itruediv__(self, f: float):
        self.c /= f
        return self

    def __repr__(self):
        return "({}, {})".format(round(self.x, 10), round(self.y, 10))

    def __neg__(self):
        c = -self.c
        return Point(c.real, c.imag)

    def __eq__(self, p):
        return abs(self.c - p.c) < EPS

    def __abs__(self):
        return abs(self.c)

    
    def __lt__(self, p):
        return self.x - p.x < -EPS or self.x - p.x < EPS and self.y - p.y < -EPS

    def __le__(self, p):
        return self.x - p.x < -EPS or self.x - p.x < EPS and self.y - p.y < EPS

    def __gt__(self, p):
        return self.x - p.x > EPS or self.x - p.x > -EPS and self.y - p.y > EPS

    def __ge__(self, p):
        return self.x - p.x > EPS or self.x - p.x > -EPS and self.y - p.y > -EPS

    @staticmethod
    def ccw(a, b, c):
        """
        線分 ab に対する c の位置
        線分上にあるか判定するだけなら on_segment とかのが速い
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
        :param Point a:
        :param Point b:
        :param Point c:
        """
        b = b - a
        c = c - a
        det = b.det(c)
        if det > EPS:
            return Point.CCW_COUNTER_CLOCKWISE
        if det < -EPS:
            return Point.CCW_CLOCKWISE
        if b.dot(c) < -EPS:
            return Point.CCW_ONLINE_BACK
        if b.dot(b - c) < -EPS:
            return Point.CCW_ONLINE_FRONT
        return Point.CCW_ON_SEGMENT

    def dot(self, p):
        """
        内積
        :param Point p:
        :rtype: float
        """
        return self.x * p.x + self.y * p.y

    def det(self, p):
        """
        外積
        :param Point p:
        :rtype: float
        """
        return self.x * p.y - self.y * p.x

    def dist(self, p):
        """
        距離
        :param Point p:
        :rtype: float
        """
        return abs(self.c - p.c)

    def norm(self):
        """
        原点からの距離
        :rtype: float
        """
        return abs(self.c)

    def phase(self):
        """
        原点からの角度
        :rtype: float
        """
        return cmath.phase(self.c)

    def angle(self, p, q):
        """
        p に向いてる状態から q まで反時計回りに回転するときの角度
        -pi <= ret <= pi
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return (cmath.phase(q.c - self.c) - cmath.phase(p.c - self.c) + PI) % TAU - PI

    def area(self, p, q):
        """
        p, q となす三角形の面積
        :param Point p:
        :param Point q:
        :rtype: float
        """
        return abs((p - self).det(q - self) / 2)

    def projection_point(self, p, q, allow_outer=False):
        """
        線分 pq を通る直線上に垂線をおろしたときの足の座標
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A&lang=ja
        :param Point p:
        :param Point q:
        :param allow_outer: 答えが線分の間になくても OK
        :rtype: Point|None
        """
        diff_q = q - p
        
        r = (self - p).dot(diff_q) / abs(diff_q)
        
        phase = diff_q.phase()

        ret = Point.from_polar(r, phase) + p
        if allow_outer or (p - ret).dot(q - ret) < EPS:
            return ret
        return None

    def reflection_point(self, p, q):
        """
        直線 pq を挟んで反対にある点
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B&lang=ja
        :param Point p:
        :param Point q:
        :rtype: Point
        """
        
        r = abs(self - p)
        
        angle = p.angle(q, self)
        
        angle = (q - p).phase() - angle
        return Point.from_polar(r, angle) + p

    def on_segment(self, p, q, allow_side=True):
        """
        点が線分 pq の上に乗っているか
        Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_C&lang=ja
        :param Point p:
        :param Point q:
        :param allow_side: 端っこでギリギリ触れているのを許容するか
        :rtype: bool
        """
        if not allow_side and (self == p or self == q):
            return False
        
        
        return abs((p - self).det(q - self)) < EPS and (p - self).dot(q - self) < EPS

    @staticmethod
    def circumcenter_of(p1, p2, p3):
        """
        外心
        :param Point p1:
        :param Point p2:
        :param Point p3:
        :rtype: Point|None
        """
        if abs((p2 - p1).det(p3 - p1)) < EPS:
            
            return None
        
        a = (p2.x - p3.x) ** 2 + (p2.y - p3.y) ** 2
        b = (p3.x - p1.x) ** 2 + (p3.y - p1.y) ** 2
        c = (p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2
        num = p1 * a * (b + c - a) + p2 * b * (c + a - b) + p3 * c * (a + b - c)
        den = a * (b + c - a) + b * (c + a - b) + c * (a + b - c)
        return num / den

    @staticmethod
    def incenter_of(p1, p2, p3):
        """
        内心
        :param Point p1:
        :param Point p2:
        :param Point p3:
        """
        
        d1 = p2.dist(p3)
        d2 = p3.dist(p1)
        d3 = p1.dist(p2)
        return (p1 * d1 + p2 * d2 + p3 * d3) / (d1 + d2 + d3)


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

h = Point.from_polar(A, (H / 12 + M / 60 / 12) * math.pi * 2)
m = Point.from_polar(B, (M / 60) * math.pi * 2)
print(h.dist(m))

Solution (Python):
import sys
import math

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

cA = 360*H/12 + 30 * M/60
cB = 360*M/60
cC = abs(cA - cB)
if cC > 180:
    cC = 360 - cC

coscC = math.cos(math.radians(cC))
C = A**2 + B**2 - 2 * A*B*coscC

print(C**(1/2))

Solution (Python):
import numpy as np
import sys
a, b, h, m = map(int, input().split())
ang = abs((30 * h + .5 * m) % 360 - (6 * m) % 360)
ang *= np.pi / 180
print(np.sqrt(a**2 + b**2 - 2 * a * b * np.cos(ang)))
print('aaa', file=sys.stderr)

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

m = m * 6
h = h * 5 * 6 + (30 * m / 360)

if h == m:
    print(abs(b - a))
    exit()

if abs(h - m) == 180:

    print(a + b)
    exit()

a1, a2 = 0, 0
x1, y1, x2, y2 = 0,0,0,0



if h == 0:
    x1 = 0
    y1 = a
elif 0 < h < 90:
    a1 = tan(radians(90 - h))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
elif h == 90:
    x1 = a
    y1 = 0
elif 90 < h < 180:
    a1 = -tan(radians(h - 90))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
if h == 180:
    x1 = 0
    y1 = -a
if 180 < h < 270:
    a1 = tan(radians(270 - h))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1
if h == 270:
    x1 = -a
    y1 = 0
if 270 < h < 360:
    a1 = -tan(radians(h - 270))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1



if m == 0:
    x2 = 0
    y2 = b
elif 0 < m < 90:
    a2 = tan(radians(90 - m))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
elif m == 90:
    x2 = b
    y2 = 0
elif 90 < m < 180:
    a2 = -tan(radians(m - 90))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
if m == 180:
    x2 = 0
    y2 = -b
if 180 < m < 270:
    
    a2 = tan(radians(270 - m))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2
if m == 270:
    x2 = -b
    y2 = 0
if 270 < m < 360:
    a2 = -tan(radians(m - 270))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2





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

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

Solution (Python):
import math

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

ang=abs(h*0.5-m*6)
if ang > 180:
  ang = 360-ang
if ang==180:
  print(a+b)
elif(ang==0):
  print(abs(b-a))
else:
  ans=(a**2)+(b**2)-(2*a*b*math.cos(math.radians(ang)))
  print(math.sqrt(ans))

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

t_angle = (h * 30) + (m * 0.5) 
b_angle = m * 6 
if t_angle - b_angle == 0:
  print(abs(a - b))
  exit()
space_angle = abs(b_angle - t_angle)
c2 = (a * a + b * b) - (2 * a * b * numpy.cos(numpy.radians(space_angle)))
print(numpy.sqrt(c2))

Solution (Python):
import math

pi = math.acos(-1)

a, b, h, m = (int(x) for x in input().split())

s_ang = h * 30 + m * 0.5
l_ang = m * 6

ang = min(abs(s_ang - l_ang), 360-abs(s_ang-l_ang))

rad = math.radians(ang)

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

if ang == 0:
    c = abs(a-b)
elif ang == 180:
    c = a+b
    
print('{:.10f}'.format(c))

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

t_angle = (h * 30) + (m * 0.5) 
b_angle = m * 6 
space_angle = abs(b_angle - t_angle)
c2 = (a * a + b * b) - (2 * a * b * numpy.cos(numpy.radians(space_angle)))
print(numpy.sqrt(c2))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
a = math.pi*(H / 6 + M /360)
b = math.pi*M / 30
print(abs(A*complex(math.cos(a),math.sin(a))-B*complex(math.cos(b),math.sin(b))))

Solution (Python):
import math
A, B, H, M = map(int, input().split())
ang1 = 30*H + M/2
ang2 = 6*M



ang = abs(ang1- ang2)/180*math.pi


out =math.sqrt(A*A + B*B - 2*A*B*math.cos(ang))
print(str(out))

Solution (Python):
import math

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

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

diff = H - M

if diff < 0:
    if diff < -180:
        diff = 180 - abs(diff + 180)
    else:
        diff = abs(diff)

if diff > 180:
    diff = 180 - (diff - 180)
print(math.sqrt(A**2 + B**2 - (2 * A * B * math.cos(math.radians(diff)))))

Solution (Python):


import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def solve(A, B, H, M):
    a = math.pi * H / 6 + math.pi * M /360
    b = math.pi * M / 30
    print(abs(A*complex(math.cos(a),math.sin(a))-B*complex(math.cos(b),math.sin(b))))


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

if __name__ == '__main__':
    main()

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

L = (60 * H + M) / 2
S = M * 6
dig = L - S


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

Solution (Python):

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

    hr = H/12 + (M/60)/12
    mr = M/60
    rad = math.pi * 2 * (hr-mr)
    req = (A*A + B*B) - (2*A*B) * math.cos(rad)
    print(req**0.5)

if __name__ == "__main__":
    resolve()

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

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

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

H = 30 * h + (m/2)
M = 6 * m
theta = abs(H-M)
if theta == 0 or theta == 360:
  print(abs(a-b))
  exit()
if theta > 180:
  theta = 360 - theta

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

Solution (Python):
import math
a,b,h,m = map(int, input().split())
if h > 12:
    h_c = h-12
else:
    h_c = h
p_d = 6*(abs((h_c)*5+5*(m/60) - m)) 
if p_d >= 180:
    p_d2 = 360 - p_d 
    d_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(p_d2))
    print(math.sqrt(d_2))
else:
    d_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(p_d))
    print(math.sqrt(d_2))

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

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()
	
    r1 = h * 30 + (m / 60) * 30
    r2 = m * 6
    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()