Atcoder abc 168 C

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.

The clock at <var>9</var> o'clock


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.

The clock at <var>10:40</var>

思路:余弦定理。

#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;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值