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
#include <iostream>
#include <iomanip>
using namespace std;
#define vs 6.
#define vm 1./double(10)
#define vh 1./double(120) int main()
{
double D;
double T[3]= {(360./(vm-vh)),(360./(vs-vm)),(360./(vs-vh))}; ///时分 分秒 时秒 的相对周期
while(cin>>D && D!=-1)
{
double HS[3]= {(D/360.)*T[0],(D/360.)*T[1],(D/360.)*T[2]}; ///存储每对针的開始Happy时间
double HE[3]= {(360.-D)/360.*T[0],((360.-D)/360.*T[1]),((360.-D)/360.*T[2])}; ///存储每对针的结束Happy时间
double happyTime=0.,nextHS=HS[0],nextHE=min(HE[1],HE[2]);
while(HS[1]<43200-(D/360.)*T[0] && HS[2]<43200-(D/360.)*T[0])
{
nextHS= max(HS[0],max(HS[1],HS[2]));
nextHE= min(HE[0],min(HE[1],HE[2]));
happyTime += (nextHE-nextHS)>0.?nextHE-nextHS:0.;
for(int i=0; i<3; i++)
{
HS[i]+=(nextHE-HE[i]<0.?HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.;
HE[i]+=(nextHE-HE[i]<0.? HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.;
}
}
double result= happyTime/432.;
cout<<setiosflags(ios::fixed)<<setprecision(3)<<result<<endl;
}
return 0;
}

这个问题由特定牛的回答,门户:丹尼尔问题解决地址

Tick and Tick------HDOJ杭州电(无法解释,直接看代码)的更多相关文章

  1. hdu 1290 竭诚为杭州电礼物50周年

    专门为杭州电50周年礼事 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. hdu1006 Tick and Tick

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

  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. 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 1006 Tick and Tick

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

  7. A == B ?(杭州电2054)

    A == B ? Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  8. 杭州电acm理工大舞台版

    我要参加全国软件设计大赛C/C++学生语言组,前一个假设<C训练和演习,并总结手>没看完,请阅读上述并根据所作的训练,然后做下面的练习. 门户:http://blog.csdn.net/l ...

  9. Tick and Tick

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

随机推荐

  1. iOSSingleton设计模式详细的说明教程

    iOS有很多的设计模式,当然,不管是什么语言有很多的设计模式.辛格尔顿是一种之一,辛格尔顿,它从字面上是一个单独的实例,首先,它是只有一个单一的,其次,它是一个实例.我们知道,在iOS用于开发Obje ...

  2. hdu 4557 非诚勿扰 vector的应用 原来vector 可以删除指定位置元素 不过消耗大

    非诚勿扰 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  3. oracle 关于日期格式转换与使用

    在oracle中我们经常会和日期打交道,在做报表的时候经常会用日报,周报,月报之类的条件进行分组: 我写了些例子来启发下大脑 select Sysdate from dual select to_ch ...

  4. Storm具体的解释(二)、成为第一Storm申请书

         在全面介绍Storm之前,我们首先通过简单的Demo让我们来看看什么是整体感觉Storm. Storm执行模式: 本地模式(Local Mode): 即Topology(相当于一个任务,兴许 ...

  5. [渣译文] SignalR 2.0 系列: 开始使用SignalR 2.0

    原文:[渣译文] SignalR 2.0 系列: 开始使用SignalR 2.0 英文渣水平,大伙凑合着看吧…… 这是微软官方SignalR 2.0教程Getting Started with ASP ...

  6. 【程序员小助手】Emacs,最强编辑器,没有之一

    内容简介 1.Emacs简介 2.Emacs三个平台的安装与配置 3.自动补全插件 4.小编的Emacs配置文件 5.常用快捷方式 6.和版本控制系统的配合(以SVN为例) [程序员小助手]系列 在这 ...

  7. scrot-0.8

    相关库下载地址:         www.sunfreeware.com/programlistsparc10.html tar -zxvf scrot-0.8.tar.gzcd scrot-0.8. ...

  8. RH033读书笔记(14)-Lab 15 Switching Users and Setting a Umask

    Lab 15 Switching Users and Setting a Umask Goal: Become familiar with the use of several essential c ...

  9. Windows 驱动发展基金会(九)内核函数

    Windows 驱动发展基金会系列,转载请注明出处:http://blog.csdn.net/ikerpeng/article/details/38849861 这里主要介绍3类Windows的内核函 ...

  10. Oracle 11G DataGuard生产环境又一次启动具体过程

     场景,重新启动数据库,不重新启动linux系统,所以不用考虑监听程序,#linux输入lsnrctl start1 数据库关闭1.1 关闭主库SHUTDOWN IMMEDIATE; SQL> ...