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

本人实在太菜:

参考自该博主,顺便附上链接膜一波:https://blog.csdn.net/yuyanggo/article/details/45765811

解析:这道题,其实想通了也不难,甚至可以说太简单了。

           时钟的时针、分针、秒针一天内的三次重合点:0:00  12:00   24:00

           所以计算这道题的是时候,只需要考虑0:00到12:00即可。

设:ws     表示秒针的角速度

                   wm    表示分针的角速度

                   wh     表示时针的角速度

                

                  wsm=ws-wm   表示秒针相对于分针的角速度 

                  wsh=ws-wh     表示秒针相对于时针的角速度

                  wmh=wm-wh   表示分针相对于时针的角速度

                  

            那么就有:(t1,t2,t3<=12*60*60)

360*(i-1)+d<=wsm*t1<=360*i-d

                  360*(j-1)+d<=wsh*t2<=360*j-d

                  360*(k-1)+d<=wmh*t3<=360*k-d

                

            t1、t2、t3可取时间的交集即为答案。

           

           具体实现如下:

              用 sum 来记录happy time,以秒为单位。

1.枚举 i ,得到 t1  与 i 对应的左右界:L、R

                若 L>=12*60*60 退出循环。

2.枚举 j ,得到 t2  与 j 对应的左右界:L2、R2。

                此时应满足[L2,R2]∩[L,R] ≠ 空集。

3.枚举 k ,得到t3 与 k 对应的左右界:L3、R3

                 此时应满足[L3,R3]∩[L2,R2] ≠ 空集,则 [L3,R3]能使上述三个不等式均成立,为happy time。

                 sum+=R3-L3。

代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
using namespace std; double sum,d,wsm,wsh,wmh; int main() {
wsm=59/10.0,wsh=719/120.0,wmh=11/120.0;
double l,r,l2,r2,l3,r3;
int i,j,k;
while(scanf("%lf",&d),d>-0.5) {
for(sum=0,i=1;; i++) {
l=(360*i-360+d)/wsm;
r=(360*i-d)/wsm;
if(l>12*60*60)break; j=(int)((l*wsh+d)/360);
if((360*j-d)/wsh<=l)j++;
for(;; j++) {
l2=(360*j-360+d)/wsh;
r2=(360*j-d)/wsh;
if(l2<l)l2=l;
if(r2>r)r2=r;
if(l2>=r2)break;
k=(int)((l2*wmh+d)/360);
if((360*k-d)/wmh<=l2)k++;
for(;; k++) {
l3=(360*k-360+d)/wmh;
r3=(360*k-d)/wmh;
if(l3<l2)l3=l2;
if(r3>r2)r3=r2;
if(l3>=r3)break;
sum+=r3-l3;
}
}
}
printf("%.3lf\n",sum/(12*60*60)*100);
}
return 0;
}

最新文章

  1. [课程设计]Scrum 3.1 多鱼点餐系统开发进度(第三阶段项目构思与任务规划)
  2. 百度编辑器Ueditor的简单调用
  3. ASCII转义字符
  4. 压力测试 tpcc-mysql
  5. HTML父子页面通信问题(showModalDialog)
  6. 一个正整数N,拆成任意个正整数之和,怎样使这些数的乘积最大
  7. Spting使用memcached
  8. hdu4553(线段树)
  9. Python第一行代码
  10. SQL优化 MySQL版 - B树索引详讲
  11. Cartographer安装
  12. 前端测试框架Jest系列教程 -- Expect(验证)
  13. MVC面试问题与答案
  14. html5-增强的表单-表单的重写
  15. 如何修改电脑的本地网卡(非笔记本无限网卡)的mac地址
  16. Nginx系列6之-rewirte功能使用案例总结
  17. sql server 备份恢复效率
  18. (动态规划)有 n 个学生站成一排,每个学生有一个能力值,从这 n 个学生中按照顺序选取kk 名学生,要求相邻两个学生的位置编号的差不超过 d,使得这 kk 个学生的能力值的乘积最大,返回最大的乘积
  19. SSH 整合 (Maven)
  20. [EffectiveC++]item17:以独立语句将newed对象置入智能指针

热门文章

  1. 90行代码让微信地球转起来,太酷了!(python实现)
  2. MySQL 插入或更新
  3. Java 多态 接口继承等学习笔记
  4. one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3, 1280, 28, 28]], which is output 0 of LeakyReluBackward1, is at version 2;
  5. ReentrantLock与synchronized 源码解析
  6. 怎么写简历,简历才不会被丢到非洲&amp;#127757;
  7. three.js 制作机房(下)
  8. vue-loader处理vue文件
  9. AS报错:gradle project sync failed
  10. Windows 安装 kafka