C - : (Colon)
Time Limit: 2 sec / Memory Limit: 1024 MB
Score: 300300 points
Problem Statement
Consider an analog clock whose hour and minute hands are AA and BB 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 1212 hours and 11 hour to make one full rotation, respectively.
At 00 o'clock, the two hands overlap each other. HH hours and MM minutes later, what is the distance in centimeters between the unfixed endpoints of the hands?
Constraints
- All values in input are integers.
- 1≤A,B≤10001≤A,B≤1000
- 0≤H≤110≤H≤11
- 0≤M≤590≤M≤59
Input
Input is given from Standard Input in the following format:
AA BB HH MM
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−910−9.
Sample Input 1 Copy
Copy
3 4 9 0
Sample Output 1 Copy
Copy
5.00000000000000000000
The two hands will be in the positions shown in the figure below, so the answer is 55 centimeters.
Sample Input 2 Copy
Copy
3 4 10 40
Sample Output 2 Copy
Copy
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.
思路:余弦定理。
#include<iostream>
#include<cmath>
#define dou double
using namespace std;
const dou pie = acos(-1.0);
int main()
{
dou a,b,h,m;
cin>>a>>b>>h>>m;
double x = h * 60 + m;
x /= 720;
x *= 2 * pie;
double y = m / 60 * 2 * pie;
double z = abs(x - y);
dou ans = sqrt(a*a + b*b -2*a*b*cos(z));
printf("%.9lf",ans);
return 0;
}