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: Wrong Answer)


#include<bits/stdc++.h>
#define int long long int
#define boost ios_base::sync_with_stdio(false)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repp(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//#define test int t;cin>>t; while(t--)
#define vi vector<int> 
#define mi map<int,int> 
#define rrep(i,a,b) for(int i=a;i>=b;i--)
//typedef pair <int,int> pii
//typedef vector<pii> vpi
#define build(arr,n) { int arr[n+1]; repp(i,1,n)cin>>arr[i]; }
#define buildv(v,n) { vi v; repp(i,1,n){int x; cin>>x; v.pb(x);} } 
#define in_edges(m) repp(i,1,m){int a,b; cin>>a>>b; adj[a].pb(b); adj[b].pb(a);}
#define mod 1000000007
#define db double
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899
#define mx(arr) {*max_element(arr+1,arr+n+1);} 
using namespace std;
//vector<int> adj[100003];
//int vis[100003]={0};
//int dp[n+1]={0};
//vector<int> leaf;
signed main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    db dh=0,dm=0;
    dh=(h)*30;
    dh+=(m/2);
    if(m)
    dm=(m*6);
    db angle=abs(dh-dm);
    //cout<<angle<<endl;
    db chck=(pi/180)*angle;
    db chckk=360-chck;
    db fang=min(chck,chckk);
    //cout<<chck<<endl;
    db fa=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(fang));
    cout<<setprecision(50)<<fa;
    
}