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 sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


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


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count





A,B,H,M = inputIL()

h = H%12

a = (30*h + M/2)/180*math.pi
b = (M*6)/180*math.pi

x1,y1 = math.sin(a)*A ,math.cos(a)*A ,
x2,y2 = math.sin(b)*B ,math.cos(b)*B ,

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

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







ado = math.pi*(h/6 + m/360)
bdo = math.pi*(m/30)
ax = a*math.cos(ado)
ay = a*math.sin(ado)
bx = b*math.cos(bdo)
by = b*math.sin(bdo)
print(math.sqrt((bx-ax)**2 + (by-ay)**2))

Solution (Python):

import math

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

deg_A = 30*H+M/2
deg_B = 6*M
deg = deg_A-deg_B

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

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

A,B,H,M=map(int,input().split())
t=pi*(60*H+M)/360
s=pi*M/30
X=(A*sin(t),A*cos(t))
Y=(B*sin(s),B*cos(s))
print(sqrt((X[0]-Y[0])**2+(X[1]-Y[1])**2))

Solution (Python):
import math
a,b,h,m=list(map(int,input().split()))
h+=m/60
ad=h*math.pi/6
bd=h*2*math.pi

ax=math.cos(ad)*a
ay=math.sin(ad)*a
bx=math.cos(bd)*b
by=math.sin(bd)*b

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

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

t1 = 2 * np.pi * m /60

t2 = 2 * np.pi * ( 60*h+m)/(60*12)

print(np.sqrt(a**2 + b**2 - 2*a*b*np.cos(t2-t1)))

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


ji = 0.5 * (h * 60 + m)
fu = 6 * m

ns = min(360 - abs(ji - fu),abs(ji - fu))


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

Solution (Python):
from math import cos, radians

A,B,H,M = [int(i) for i in input().split()]
ans = lambda a,b,c: (a**2 + b**2 - 2*a*b*cos(radians(c)))**0.5
ang = min(abs(H*30 + M*0.5 - M*6), 360 - abs(H*30 + M*0.5 - M*6))
print(ans(A,B,ang))

Solution (Python):

import math

def main():
    A, B, H, M = map(int, input().split())
    s = 30*H+0.5*M
    l = 6 * M
    C = A**2 + B**2 - 2*A*B*math.cos(math.radians(abs(l-s)))
    print(C**0.5)

if __name__ == "__main__":
    main()

Solution (Python):


import sys, math
sys.setrecursionlimit(300000)


def solve(A: int, B: int, H: int, M: int):
    m = 360 * (M / 60)
    h = 30 * H + 30 / 60 * M
    a = (m - h) % 360
    
    ret = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(a / 180 * math.pi))
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    H = int(next(tokens))  
    M = int(next(tokens))  
    solve(A, B, H, M)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    A,B,H,M=MI()
    ad=0.5*(M+H*60)
    bd=6*M
    import cmath
    import itertools
    import math
    import sys


    sys.setrecursionlimit(10 ** 9)
    IINF = 10 ** 18
    MOD = 10 ** 9 + 7
    


    INF = float("inf")
    PI = cmath.pi
    TAU = cmath.pi * 2
    EPS = 1e-10
    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)

        @staticmethod
        def ccw(a, b, c):
            """
            線分 ab に対する c の位置
            線分上にあるか判定するだけなら on_segment とかのが速い
            :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 c.norm() - b.norm() > 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 を通る直線上に垂線をおろしたときの足の座標
            :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 を挟んで反対にある点
            :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 の上に乗っているか
            :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
    import math
    
    ap=Point.from_polar(A,ad*2*PI/360)
    bp=Point.from_polar(B,bd*2*PI/360)
    ans=ap.dist(bp)
    print(ans)


main()

Solution (Python):
from math import cos, pi

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

SA = 30 * H + M / 2
LA = 6 * M

DA = abs(SA - LA)
DA = min(DA, 360 - DA)

C2 = A ** 2 + B ** 2 - 2 * A * B * cos(DA / 360 * 2 * pi)
print(C2 ** 0.5)

Solution (Python):
import sys
input=lambda: sys.stdin.readline().rstrip()
import math
a,b,h,m=map(int,input().split())
d=h*30+0.5*m-6*m
ans=(a**2+b**2-2*a*b*math.cos(math.radians(d)))**0.5
print(ans)

Solution (Python):
import math

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

angle = (5.5*m-30*h)%360
print("%.9f" % (a**2+b**2-2*a*b*math.cos(math.radians(angle)))**(1/2))

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

ans = sqrt(a**2 + b**2 - 2*a*b*cos((h/12+m/720-m/60)*2*pi))
print(ans)

Solution (Python):
import math
a,b,h,m=map(int,input().split())
d=h*30-5.5*m
if d<0:
    d+=360
if d>180:
    d=360-d
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(d))))

Solution (Python):
import math
a,b,h,m = map(int,input().split())
aangle = (h*60+m)*0.5
bangle = 6*(h*60+m)%360
angle = min(abs(aangle-bangle),360-abs(aangle-bangle))
rad = math.radians(angle)
c = a**2+b**2-2*a*b*math.cos(rad)
print(c**0.5)

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

Solution (Python):
from math import sin,cos,pi
a, b, h, m = [int(i) for i in input().split()]
t = (h + m / 60)*2*pi

ax, ay = a * cos(t / 12), a * sin(t / 12)
bx, by = b * cos(t), b * sin(t)
print(((ax-bx)**2+(ay-by)**2)**0.5)

Solution (Python):
from math import cos, pi
a, b, h, m = map(int, input().split())
t = pi * abs(60 * h - 11 * m) / 360
print((a ** 2 + b ** 2 - 2 * a * b * cos(t)) ** .5)

Solution (Python):
from math import *

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

p = h * 30 + m / 2
q = 6 * m
r = abs(p - q)
r = min(r, 360 - r)
res = a * a + b * b - 2 * a * b * cos(radians(r))
print("%.12f" % res ** 0.5)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from math import pi, sqrt, cos
    input = sys.stdin.readline

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

    ta = pi * 2 * (H + M / 60) / 12
    tb = pi * 2 * M / 60
    t = abs(ta-tb)

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

a, b, h, m = nm()
anm = math.pi * 2 * m / 60
anh = math.pi * 2 * (60 * h + m) / 720
f = abs(anm - anh)
f = min(f, 2 * math.pi - f)
c2 = a*a + b*b - 2*a*b*math.cos(f)
print(c2**.5)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

a,b,h,m = MAP()
theta = abs(360 * m / 60 - 360 * (h + m / 60) / 12) * pi / 180
ans = sqrt(a ** 2 + b ** 2 - 2 * a * b * cos(theta))
print(ans)

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

Solution (Python):
a,b,h,m=map(int,input().split())
from math import pi,cos
theta=abs(30*h-6*m+m/2)*pi/180

print((a**2+b**2-2*a*b*cos(theta))**(1/2))

Solution (Python):

import bisect
import collections
import sys
import math

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62


def solve(A: int, B: int, H: int, M: int):
    m_deg = M / 60 * 2*math.pi
    h_deg = (H + M / 60) / 12 * 2*math.pi

    a_x, a_y = A * math.cos(h_deg), A * math.sin(h_deg)
    b_x, b_y = B * math.cos(m_deg), B * math.sin(m_deg)

    print(((a_x - b_x) ** 2 + (a_y - b_y) ** 2) ** 0.5)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  
    B = int(next(tokens))  
    H = int(next(tokens))  
    M = int(next(tokens))  
    solve(A, B, H, M)


if __name__ == '__main__':
    main()

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

x1 = a * math.cos(math.pi * (60 * h + m)/60/6)
x2 = b * math.cos(math.pi * m/30)
y1 = a * math.sin(math.pi * (60 * h + m)/60/6)
y2 = b * math.sin(math.pi * m/30)

d2 = (x1 - x2) ** 2 + (y1 - y2) ** 2
print(d2 ** .5)

Solution (Python):
import sys
input = sys.stdin.readline
import math
a, b, h, m = map(int,input().split())
c = ((h%12) * 60 + m) / (60 * 12)
d = m / 60
t = abs(c-d) * 2 * math.pi

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    a,b,h,m = LI()
    x = 30*h+0.5*m
    y = 6*m
    cos = math.cos(abs(x-y)/180*3.141592653589793238)
    c = a**2+b**2-2*a*b*cos
    print(c**0.5)
    return


if __name__ == "__main__":
    solve()