Tick and Tick

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20120    Accepted Submission(s): 5262

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
 
Author
PAN, Minghao
 
Source
分析:

三个指针走的角速度:

秒针速度S = 6°/s,分针速度M = (1/10)°/s,时针速度H = (1/120)°/s

这三个指针两两之间的相对速度差为:

秒时相差S_H = (719/120)°/s,秒分相差S_M = (59/10)°/s,分时相差M_H = (120/11)°/s

相差一度需要的时间为

秒时相差SH = (120/719)s/度,秒分相差SM = (10/59)s/度,分时相差MH = (120/11)s/度

相差360°需要的时间为

秒时相差tSH = 43200.0/719,秒分相差tSM = 3600.0/59,分时相差tMH = 43200.0/11

算出两两指针在43200s(12小时)内满足条件时间的区间的交集。

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>

using namespace std;
///秒针角速度 6度/s, 分针0.1度/s,时针1/120度/s
const double sh = 719.0/120 , sm = 59.0/10, mh = 11.0/120;///三个指针两两相对角速度。
const double tsh = 43200.0 / 719, tsm = 3600.0 / 59, tmh = 43200.0 / 11;///三个指针两两相差360度所需的时间。
///将相对角速度变成周期。(即两针间需要多久出现夹角的循环)
/// 同样可求得三个周期的最小公倍数为 43200 秒,即12小时,

double max1(double a, double b, double c)
{
return max(a, max(b, c));
}
double min1(double a, double b, double c)
{
return min(a, min(b, c));
}
int main(void)
{
int D;

while(scanf("%d", &D), D != -1)
{
double bsh, bsm, bmh, esh, esm, emh, total, beginn, endd;
///第一次满足条件的时间。(开始时间)
bsh = D / sh;
bsm = D / sm;
bmh = D / mh;
///第一次出现不满足条件的时间。(结束时间)
esh = (360 - D) / sh;
esm = (360 - D) / sm;
emh = (360 - D) / mh;

total = 0;

for(double bt1 = bsh, et1 = esh; et1<= 43200.000001; bt1 += tsh, et1 += tsh)
{
for(double bt2 = bsm, et2 = esm; et2 <= 43200.000001; bt2 += tsm, et2 += tsm)
{
///判断是否有交集。
if(bt2 > et1)
break;

if(et2 < bt1)
continue;

for(double bt3 = bmh, et3 = emh; et3 <= 43200.000001; bt3 += tmh, et3 += tmh)
{
if(bt3 > et1 || bt3 > et2)
break;

if(et3 < bt1 || et3 < bt2)
continue;

beginn = max1(bt1, bt2, bt3);
endd = min1(et1, et2, et3);

total += (endd - beginn);
}

}
}

printf("%.3f\n", total / 432);

}
return 0;
}

HDU 1006 模拟的更多相关文章

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

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

  2. HDU 1006 [Tick Tick]时钟问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...

  3. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  4. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

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

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

  6. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  7. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  8. HDU/5499/模拟

    题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...

  9. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...

随机推荐

  1. 【UEFI】---基于UEFI编程的基本思路

    最近基于UEF在写代码的时候,发现由于粗心总是出现很多问题,而且都是一些小问题.虽然UEFI玩了挺久,但是也没梳理一下思路.借此机会整理一下: UEFI对复杂的BIOS代码做了很好的封装和模块化.  ...

  2. HTTP图解笔记(一)—— 第1章 了解Web及网络基础

    TCP/IP协议族 网络是在TCP/IP协议族的基础上运作的,HTTP是一个子集 OSI四层: 应用层:通用的应用服务协议,FTP.DNS.HTTP ↓ 传输层:提供计算机之间的数据传输,TCP.UD ...

  3. proxy应用场景

    //场景一:可以修改对象的值let o = { name: 'xiaoming', price: 190 } let d = new Proxy(o,{ get (target,key){ if(ke ...

  4. 玩转Django2.0---Django笔记建站基础十(一)(常用的Web应用程序)

    第十章 常用的Web应用程序 Django为开发者提供了常见的Web应用程序,如会话控制.高速缓存.CSRF防护.消息提示和分页功能.内置的Web应用程序大大优化了网站性能,并且完善了安全防护机制,而 ...

  5. 靶机-droopyCTF Walkthrough

    droopyCTF https://www.vulnhub.com/?q=droopy&sort=date-des&type=vm CTF镜像合集:https://www.vulnhu ...

  6. 我的C++开发工具链

    工欲善其事,必先利其器.想要干好活,顺手的工具是必不可少的.来分享下我的C++开发工具链. 平台:Windows 编译器:MSVC IDE:Visual Studio 版本控制:TortoiseGit ...

  7. GitHub Top 微信小程序——在家中憋了几天写点代码吧

    GitHub Top 本项目为 GitHub 热点项目微信小程序客户端,首页仅推荐一个热点项目,这个项目往往是社会热门事件所催生的一个项目,如 996.ICU.wuhan2020,所推荐项目标准为:积 ...

  8. VScode前端插件推荐

    工欲善其事,必先利其器,安利一波前端插件. Chinese (Simplified) Language Pack for Visual Studio CodeVScode汉化插件 Beautify代码 ...

  9. Day7-Python3基础-面向对象进阶

    内容: 面向对象高级语法部分异常处理 经典类vs新式类 静态方法.类方法.属性方法 类的特殊方法 反射 Socket开发基础 面向对象高级语法部分 静态方法       通过@staticmethod ...

  10. Java错误:找不到类文件或者未加载主类

    使用java命令执行.class文件时,java只会查找环境变量CLASSPATH中的目录,并会不查找当前目录,所以只要把当前目录”."加入到CLASSPATH中就可以了.