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;
}

HDU-Tick and Tick的更多相关文章

  1. HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...

  2. HDU 1006 Tick and Tick 时钟指针问题

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  3. hdu 1006 Tick and Tick 有技巧的暴力

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. hdu 1006 Tick and Tick

    Tick and Tick Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hdu1006 Tick and Tick

    原题链接 Tick and Tick 题意 计算时针.分针.秒针24小时之内三个指针之间相差大于等于n度一天内所占百分比. 思路 每隔12小时时针.分针.秒针全部指向0,那么只需要计算12小时内的百分 ...

  6. HDU 1006 Tick and Tick 解不等式解法

    一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...

  7. [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]

    Problem Description The three hands of the clock are rotating every second and meeting each other ma ...

  8. 1006 Tick and Tick

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题意: 24小时中,三个指针之间超过某个度数的时间占所有时间的百分比是多少. 思路:主要是物理和数学 ...

  9. Tick and Tick

    The three hands of the clock are rotating every second and meeting each other many times everyday. F ...

  10. hdu_1006 Tick and Tick(暴力模拟)

    hdu1006 标签(空格分隔): 暴力枚举 好久没有打题了,退队了有好几个月了,从心底不依赖那个人了,原来以为的爱情戏原来都只是我的独角戏.之前的我有时候好希望有个人出现,告诉自己去哪里,做什么,哪 ...

随机推荐

  1. Pytest单元测试框架-allure测试报告

    Allure Test Report 对于不同的编程语言,有很多很酷的测试框架.不幸的是,它们中只有少数能够提供测试执行输出的良好表示.Qameta软件测试团队正在致力于Allure--一个开源框架, ...

  2. Spring IoC是如何进行依赖注入的

    依赖注入(DI) DI(Dependency Injection),Spring IoC 不是一种技术,而是一种思想,通过这种思想,能够指导我们设计出松耦合的程序代码.而Spring IoC这个思想的 ...

  3. xadmin 安装

    xadmin 安装 环境(一定要一样) Python 3.6.2 Django 2.0 安装 pip install django==2.0, 指定特定的版本 pip install https:// ...

  4. 洛谷 P4198 楼房重建

    思路 此题可转化为以下模型 给定序列\(a[1...n]\),支持单点修改,每次求区间单调栈大小 \(n,Q\le 10^5\) 区间单调栈是什么呢?对于一个区间,建立一个栈,首先将第一个元素入栈,从 ...

  5. JAVA—继承及抽象类

    继承的概念 在Java中,类的继承是指在一个现有类的基础上去构建一个新的类,构建出来的新类被称作子类,现有类被称作父类,子类会自动拥有父类所有可继承的属性和方法. 与css中继承父元素属性类似 继承的 ...

  6. 2020-07-09:mysql如何开启慢查询?

    福哥答案2020-07-09: 1.参数说明 slow_query_log 慢查询开启状态slow_query_log_file 慢查询日志存放的位置(这个目录需要MySQL的运行帐号的可写权限,一般 ...

  7. Visual Studio 2017版本15.9现在可用

    本文转自 https://blogs.msdn.microsoft.com/visualstudio/2018/11/19/visual-studio-2017-version-15-9-now-av ...

  8. C#LeetCode刷题之#326-3的幂(Power of Three)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3867 访问. 给定一个整数,写一个函数来判断它是否是 3 的幂次 ...

  9. 封装react antd的form表单组件

    form表单在我们日常的开发过程中被使用到的概率还是很大的,比如包含了登录.注册.修改个人信息.新增修改业务数据等的公司内部管理系统.而在使用时这些表单的样式如高度.上下边距.边框.圆角.阴影.高亮等 ...

  10. Mac中的垃圾文件的清理

    一 前言 最近发现mac的存储空间不够了,看一下系统的存储空间如下图所示,这个其他占了160+G的存储空间,那么这个其他到底包含什么东西呢?在网上查了很久,找到一种比较认可的说法是这样的: 不同Mac ...