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 in C (GCC 9.2.1) (judge verdict: Accepted)

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define M_PI			3.1415926535897932384626433832795		// 円周率

// 内部構造体 - 座標情報
typedef struct Point {
	double mdX, mdY;											// 座標
} Point;

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// ２点間の距離 - 取得
double
fGetLen(
	Point *pzpPoint1			// <I> 座標１
	, Point *pzpPoint2			// <I> 座標２
)
{
	double ldX = pzpPoint1->mdX - pzpPoint2->mdX;
	double ldY = pzpPoint1->mdY - pzpPoint2->mdY;
	return sqrt(ldX * ldX + ldY * ldY);
}

// 座標 - 取得
int
fGetPoint(
	double pdAngle				// <I> 角度
	, double pdLen				// <I> 長さ
	, Point *pzpPoint			// <O> 座標
)
{
	pdAngle *= 2.0 * M_PI / 360.0;
	pzpPoint->mdX = pdLen * cos(pdAngle);
	pzpPoint->mdY = pdLen * sin(pdAngle);

	return 0;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// 値 - 取得
	double ldA, ldB;
	int liH, liM;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lf%lf%d%d", &ldA, &ldB, &liH, &liM);

	// 時
	Point lzH;
	fGetPoint((double)((15 - liH) % 12) * 30.0 - (double)liM / 2.0, ldA, &lzH);

	// 分
	Point lzM;
	fGetPoint((double)((75 - liM) % 60) * 6.0, ldB, &lzM);

	// ２点間の距離 - 取得
	double ldLen = fGetLen(&lzH, &lzM);

	// 出力
	sprintf(lc1Buf, "%.10lf\n", ldLen);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}