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个指针的角速度:
- #define V_SEC 6.0 //秒针角速度:6度每秒
- #define V_MIN 0.1 //分针角速度:0.1度每秒
- #define V_HOU 1.0/120 //时针角速度:1/120度每秒
然后:这3个指针偏离0点的角度:
- #define A_SEC s*6 //秒针角度:6*s
- #define A_MIN m*6+s*0.1 //分针角度:0.1度*60s*m分钟+0.1度*s秒
- #define A_HOU h*30+m*0.5+s/120.0 //时针角度:1/120度*3600s*h小时+1/120度*60s*m分钟+1/120*s秒
4.