时针分针秒针夹角问题
来源:互联网 发布:java中try catch的用法 编辑:程序博客网 时间:2024/04/29 16:38
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
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
012090-1
Sample Output
100.0000.0006.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);} }
阅读全文
0 0
- 时针分针秒针夹角问题
- HDU 5387 Clock(计算时针与分针 时针与秒针 分针与秒针的夹角)
- 时针分针重合问题与时针、分针、秒针重合问题
- 时针,分针和秒针的重合问题
- 逻辑思维题之时针分针秒针问题
- 时针分针夹角公式与重合问题
- 时针和分针夹角的问题
- hdu 1006 时针/分针/秒针
- 面试智力题 — 时针与分针夹角度数问题
- 时针分针秒针一天到底重合几次
- 时针分针秒针一天重合几次
- hdu2076(时针和分针的夹角)
- UVA ClockHands (时针分针求夹角)
- 计算时针与分针的夹角
- 分针与时针之间夹角的计算
- HDU 2076 时针和分针夹角多大
- python题目-----计算时针分针夹角
- java钟表时针分针夹角计算器
- NYOJ 12 喷水装置(二)
- ffmpeg中的时间
- windows10 下boost.python(3.6anaconda)+dlib19.4 配置+pytorch
- 线程
- redis源码阅读步骤
- 时针分针秒针夹角问题
- LInux中存储设备的管理
- Golang游戏服务器
- Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域
- zookeeper原理及作用
- sql(join中on与where区别) / NVL函数 / oracle存储过程中is和as区别 / JAVA调用数据库存储过程
- 【Mybatis学习】Mybatis框架中的配置
- 腾讯we大会~2017
- Caisa and Pylons