时针分针秒针夹角问题
2017-11-06 19:48
225 查看
Tick and Tick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20103 Accepted Submission(s): 5255
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
0 120 90 -1
[align=left]Sample Output[/align]
100.000 0.000 6.251
题目意思是求分针时针秒针之间成的角度大于某个值时在一天的时间中所占的比例。
#include<stdio.h> #include<iostream> double MAX(double a,double b,double c) { double max=a; if(b>=max) max=b; if(c>=max) max=c; return max; } double MIN(double x,double y,double z) { double min=x; if(y<=min) min=y; if(z<=min) min=z; return min; } double TIME=43200.000001;//一天的秒数 //计算出各自的角速度 double hds=30,mds=360,sds=120*180;//单位是 度/小时 //计算之间的相对角速度 (角速度之差) 单位是度/分钟, double h_m=11.0/120,h_s=719.0/120,m_s=59.0/10; //由相对角速度计算每隔多长时间他们之间的夹角出现相同的情况 double wh_m=360.0/h_m,wh_s=360.0/h_s,wm_s=360.0/m_s; int main() { double D; double begin,end; while(scanf("%lf",&D),D!=-1) { double anstime=0; //计算各自第一次满足条件的时间 double sth_m=D/h_m,sth_s=D/h_s,stm_s=D/m_s; //计算各自第一次不能满足条件的时间 double eth_m=(360-D)/h_m,eth_s=(360-D)/h_s,etm_s=(360-D)/m_s; //开始三重循环,求出每一次满足条件的开始时间和结束时间之差,并且累加起来,就可以求得总时间 for(double st1=sth_m,et1=eth_m;et1<TIME;st1+=wh_m,et1+=wh_m) { for(double st2=sth_s,et2=eth_s;et2<TIME;st2+=wh_s,et2+=wh_s) { if(st1>et2)//h_m还没开始,h_s就结束了 continue; if(et1<st2)//h_s还没开始,h_m就结束了 break; for(double st3=stm_s,et3=etm_s=etm_s;et3<TIME;st3+=wm_s,et3+=wm_s) { if(st2>et3||st1>et3)//m_s结束了,其他还没开始 continue; if(et2<st3||et1<st3)//其他结束了,m_s还没开始 break; begin=MAX(st1,st2,st3); end=MIN(et1,et2,et3); anstime+=(end-begin); } } } printf("%.3lf\n",anstime/432); } }
相关文章推荐
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 时针分针重合问题与时针、分针、秒针重合问题
- 逻辑思维题之时针分针秒针问题
- 时钟的时针、分针和秒针重合问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 时针,分针和秒针的重合问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 面试智力题 — 时针与分针夹角度数问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- 【模拟,时针分针秒针两两夹角】【没有跳坑好兴奋】hdu - 5387 (多校#8 1008)
- 逻辑思维题之时针分针秒针问题
- 逻辑思维题之时针分针秒针问题
- HDU 5387 Clock(计算时针与分针 时针与秒针 分针与秒针的夹角)