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
 
/////////////////////////////

算法分析

秒针(S): 1s 360/60= 6 度(degree)
分针(M): 1s 360/60*60= 1/10度(degree)
时针(H): 1s 360/60*60*12= 1/120度(degree)

秒针与分针的相对速度为:
V(M,S) = 6-1/10 = 59/10 d/s;
同理, 时针与秒针 V(H,S) = 6-1/120 =719/120 d/s;
V(H,M) = 1/10-1/120 = 11/120 d/s.

秒针与分针的相遇周期为
T(M,S)= 360/V(M,S)= 3600/59;
同理, T(H,S)= 360/V(H,S)=43200/719;
T(H,M)= 360/V(H,M)=43200/11;

在一天24小时内,后12个小时与前12个小时情况完全相同,故只取12个小时即可。
则12个小时总秒数
T = 12h * 60m* 60s = 43200s

秒针与分针的相遇次数为
N(M,S)=T/T(M,S) = 59*12 = 708
同理, N(H,S)=T/T(H,S) = 719
N(H,M)=T/T(H,M) = 11

由于周期性规律可知:
假设秒针与分针之间的角度用函数F(t)表示,则 F(t)为某一时刻t两针之间的角度。
F(t+n*T(M,S)) = F(t) , 其中n为自然数,
同理, F(t+n*T(H,S)) = F(t)
F(t+n*T(H,M)) = F(t)

所以,我们只要计算出第一个周期内的各指针之间的幸福时间区段,再加上若干个各自周期后,仍为幸福区段。
假设角度差至少为D时,秒针和分针才幸福,则在第一个周期T(M,S)内,
D<= V(M,S)*t <= 360-D

解得 t1=D/V(M,S)
t2=(360-D)/V(M,S);
根据周期性,
happy(t ms) =(t1+n*T(M,S),t2+n*T(M,S)) 0 <= n < N(M,S);
同理, happy(t hs ) =(t1+n*T(H,S),t2+n*T(H,S)) 0 <= n < N(H,S);
happy(t hm) =(t1+n*T(H,M),t2+n*T(H,M)) 0 <= n < N(H,M);

最后,求得三者的交集区间长度

L = happy(t ms) X happy(t hs) X happy(t hm) ,(X表示关系交)即可。

    #include <iostream>
#include <iomanip>
using namespace std;
const int T = *, NMS = ,NHM = , NHS = ; //相遇次数
const double F = 0.0466631; //F为调节系数,使得各区间段为准确值
const double hmlen = T*F/NHM,mslen = T*F/NMS,hslen = T*F/NHS;
struct interval
{
double low,high;
};
interval andset(interval S1,interval S2)
{
interval zone;
zone.low = S1.low > S2.low ? S1.low : S2.low;
zone.high = S1.high < S2.high ? S1.high : S2.high;
if( zone.low >= zone.high )
zone.low = zone.high = 0.0;
return zone;
}
int main()
{
int D=;
while(cin>>D&&D!=-)
{
double len = 0.0;
interval ms,hs,hm; hm.low = hmlen*D/ - hmlen;
hm.high = - hm.low -hmlen; ms.low = mslen*D/ - mslen;
ms.high = - ms.low -mslen; hs.low = hslen*D/ - hslen;
hs.high = - hs.low -hslen; for(int i=,j=,k=;i<NHM;i++)
{
hm.low+=hmlen;
hm.high+=hmlen; for(;j<NMS;j++)
{
ms.low+=mslen;
ms.high+=mslen; interval temp1 = andset(hm,ms);
if(temp1.low!=||temp1.high!=)
{
for(;k<NHS;k++)
{
hs.low+=hslen;
hs.high+=hslen; interval temp2 = andset(temp1,hs);
len+=temp2.high-temp2.low;
if(hs.high>=temp1.high)
{
hs.low-=hslen;
hs.high-=hslen;
break;
}
}
}
if(ms.high>=hm.high)
{
ms.low-=mslen;
ms.high-=mslen;
break;
}
}
}
cout<<setprecision()<<fixed<<len/(*F)<<endl;
}
return ;
}

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

  1. hdu1006 Tick and Tick

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

  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(时钟,分钟,秒钟角度问题)

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

  5. hdu 1006 Tick and Tick

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

  6. Tick and Tick

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

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

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

  8. 1006 Tick and Tick

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

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

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

  10. hdu1006 Tick and Tick (数学题 借鉴了大神的博客)

    先缩短一半的时间:早上的12个小时和下午的12小时对时钟是一样的,因为时钟12小时与0小时的三针位置相同.接着就是了解到每次所有的针从有重合到再次有重合至多有一段连续的段符合三针分离度大于n.所以只要 ...

随机推荐

  1. 【BZOJ1266】[AHOI2006]上学路线route Floyd+最小割

    [BZOJ1266][AHOI2006]上学路线route Description 可可和卡卡家住合肥市的东郊,每天上学他们都要转车多次才能到达市区西端的学校.直到有一天他们两人参加了学校的信息学奥林 ...

  2. General Decimal Arithmetic 浮点算法

    General Decimal Arithmetic http://speleotrove.com/decimal/ General Decimal Arithmetic [ FAQ | Decima ...

  3. MySql 安装常见问题汇总

    说明: 以下是针对 Mac 10.11 系统 以前,安装 MySql 数据库后, 设置的密码过于复杂,想更改为简单的密码, 方便数据库的使用. 1. 关闭和启动 MySql 数据库的方法: Syste ...

  4. LinuxCentos系统安装Nginx过程记录

    网站服务 想必我们大多数人都是通过访问网站而开始接触互联网的吧.我们平时访问的网站服务就是Web网络服务,一般是指允许用户通过浏览器访问到互联网中各种资源的服务. Web网络服务是一种被动访问的服务程 ...

  5. Linux中的history命令

    history -c  清空历史命令 -w 把缓存中的历史命令写入历史命令保存文件说明: a.在用户登录的时候执行的命令会先存在缓存里 b.当用户退出的时候会把缓存里的命令写到文件里 c.用会执行命令 ...

  6. 《Python 机器学习》笔记(二)

    机器学习分类算法 本章将介绍最早以算法方式描述的分类机器学习算法:感知器(perceptron)和自适应线性神经元. 人造神经元--早期机器学习概览 MP神经元 生物神经元和MP神经元模型的对应关系如 ...

  7. Linux:Ubuntu下部署Web运行环境

    Linux:Ubuntu下部署Web运行环境 本次博客将会从三部分内容详述Ubuntu系统下Web运行环境的配置: 依次是:FTP服务器的搭建.MYSQL数据库的搭建.JDK的安装等. 参考文章如下: ...

  8. spark学习(1)--ubuntu14.04集群搭建、配置(jdk)

    环境:ubuntu14.04 jdk-8u161-linux-x64.tar.gz 1.文本模式桌面模式切换 ctrl+alt+F6 切换到文本模式 ctrl + alt +F7 /输入命令start ...

  9. 第二篇 Python图片处理模块PIL(pillow)

    本篇包含:16.Point    17.Putalpha    18.Putdata    19.Putpalette    20.Putpixel      21.Quantize     22.R ...

  10. 区块链入门级别认知(blockchain)

    区块链入门级别认知(blockchain) 前言:今天参加了迅雷关于区块链的大会,学习和感受总结一下 之前的认知在:几个混迹互联网圈关于区块链 耳熟能详的 热词 “比特币” “区块链” “挖矿” ,知 ...