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. VMware Workstation CentOS7 Linux 学习之路(4)--守护服务(Supervisor)

    目前存在三个问题 问题1:ASP.NET Core应用程序运行在shell之中,如果关闭shell则会发现ASP.NET Core应用被关闭,从而导致应用无法访问,这种情况当然是我们不想遇到的,而且生 ...

  2. crontab里的特殊符号%导致命令不能执行

    有群里的小伙伴说crontab里的任务不执行,具体是这样的 * * * * /bin/date "+%Y-%m-%d %H:%M:%S" >>/data/tmp/tes ...

  3. maven install 报错 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

    pom文件引入以下依赖 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId> ...

  4. DevExpress作为企业赞助商加入.NET基金会

    .NET基金会是一个独立的非营利组织,于2014年成立,旨在围绕 .NET 不断增长的开源技术集合,促进开放开发和协作.它是商业和社区开发人员的论坛,通过促进开放性,社区参与和快速创新来增强.NET生 ...

  5. C入门题目

    37. 反转一个3位整数 反转一个只有3位数的整数. 样例 样例 1: 输入: number = 123 输出: 321 样例 2: 输入: number = 900 输出: 9 注意事项 你可以假设 ...

  6. ninject 的 实现 的 理解

    mvc 用ninject 好像 有 的. 加上 ClassDiagram  .ClassDiagram1.rar Represents a site on a type where a value c ...

  7. 使用Route Prefix 使用属性路由 精通ASP-NET-MVC-5-弗瑞曼

  8. c#数字图像处理(十一)图像旋转

    如果平面上的点绕原点逆时针旋转θº,则其坐标变换公式为: x'=xcosθ+ysinθ   y=-xsinθ+ycosθ 其中,(x, y)为原图坐标,(x’, y’)为旋转后的坐标.它的逆变换公式为 ...

  9. MySQL基础知识清单

    学习大纲(★为重点,√其次) 一.为什么要学习数据库 二.数据库的相关概念 DBMS.DB.SQL 三.数据库存储数据的特点 四.初始MySQL MySQL产品的介绍 MySQL产品的安装 ★ MyS ...

  10. 四、Django学习之关系表介绍及使用

    关系表介绍及使用 一对一关系 xx = models.OneToOneField(to='表名',to_field='字段名',on_delete=models.CASCADE) #on_delete ...