码迷,mamicode.com
首页 > 其他好文 > 详细

1006 Tick and Tick

时间:2016-11-04 13:38:00      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:app   区间   finally   相对   for   like   用户   proc   size   

 

1006题:

Problem Description

The three hands of the clock are rotating every second and meeting each other many times everyday. Finally, they get bored of this and each of them would like to stay away from the other two. A hand is happy if it is at least D degrees from any of the rest. You are to calculate how much time in a day that all the hands are happy.

 

Input

The input contains many test cases. Each of them has a single line with a real number D between 0 and 120, inclusively. The input is terminated with a D of -1.

 

Output

For each D, print in a single line the percentage of time in a day that all of the hands are happy, accurate up to 3 decimal places.

 

Sample Input

 

0 120 90 -1

 

 

Sample Output

100.000 0.000 6.251

 

思路:

要求:时针、分针、秒针之间的间隔区间大于某个角度(这个角度由用户输入)的总时间占一天之中总时间的比例。

可以这样理解:

1.我们只需算出时钟从12点整(3个指针重合),到下一次12点整(3个指针再次重合)这12个小时的时间过程中,这3个指针之间的区间间隔大于制定角度的时间(即秒数)即可。

2.既然是算秒数,我们可以算这12个小时,也就是在720分钟当中,每分钟有多少秒这3个指针的位置符合要求。

3.于是,我们计算在h:m:s(h时m分s秒)时刻,这3个指针偏离12点整位置的角度(因为这样便于计算这3个指针的相对角度差,即它们相距的区间):

首先:这3个指针的角速度:

  1. #define V_SEC 6.0       //秒针角速度:6度每秒
  2. #define V_MIN 0.1       //分针角速度:0.1度每秒  
  3. #define V_HOU 1.0/120   //时针角速度:1/120度每秒

然后:这3个指针偏离0点的角度:

  1. #define A_SEC s*6                   //秒针角度:6*s  
  2. #define A_MIN m*6+s*0.1             //分针角度:0.1度*60s*m分钟+0.1度*s秒  
  3. #define A_HOU h*30+m*0.5+s/120.0    //时针角度:1/120度*3600s*h小时+1/120度*60s*m分钟+1/120*s秒

4.

1006 Tick and Tick

标签:app   区间   finally   相对   for   like   用户   proc   size   

原文地址:http://www.cnblogs.com/ttzm/p/6029639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!