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. [C++] WinAES问题

    WinAES这是一个很好windows CAPI包. 假设C++项目需求和java程序aes加密和通信的解密,然后WinAES代码是有问题. java的aes默认代码未设置IV和用途ECB模式. 因此 ...

  2. 玩转web之json(五)---将表单通过serialize()方法获取的值转成json

    form表单有一个serialize()方法,可以序列化表单的值,但是jquery提供的这个方法会把数据序列化为类似下面的形式: a=1&b=2&c=3&d=4 jquery并 ...

  3. elasticsearch中国字(mmseg)——手动添加字典

    elasticsearch中国文字本身并不是一个理想的插件效果.手动添加字典可以补偿在一定程度上. 后发现了几个实验,mmseg分段机制采用正向最长匹配算法.例如,抵抗"小时报"这 ...

  4. Linux在高铁项目的部署环境

    因为Linux和Java像开源.所以,现在在server基本上使用部署Linux平台即server.然后部署项目.在开发项目的过程中.程序员绝大多数仍采用最经典windows操作系统,尽管Linux也 ...

  5. js 加载初始化日期

    //初始化加载时间 $(function(){  var now = new Date();            var year = now.getFullYear();       //年   ...

  6. sql pivot、unpivot和partition by用法

    原文:sql pivot.unpivot和partition by用法 演示脚本 from sys.sysobjects where name = 'Student' AND type = 'U') ...

  7. Hibernate HQL详细说明

    1.  Hibernate HQL详细说明 1.1.  hql一个简短的引论 Hibernate它配备了一种非常强大的查询语言.这种语言看起来非常像SQL.但是不要 要对相位的语法结构似,HQL是很有 ...

  8. [原创].NET 业务框架开发实战之七 业务层初步构想

    原文:[原创].NET 业务框架开发实战之七 业务层初步构想 .NET 业务框架开发实战之七 业务层初步构想 前言:本篇主要讲述如何把DAL和BLL衔接起来. 本篇议题如下: 1.       DAL ...

  9. IBatis.net初步使用

    最近加班比较忙,时间也比较琐碎,蛮久没有写东西了.这次就总结一下自己使用IBatis.net的一些总结吧. IBatis简介 IBatis.net是一款开源的Orm框架,应该算是从java的IBati ...

  10. POJ3581:Sequence(后缀数组)

    Description Given a sequence, {A1, A2, ..., An} which is guaranteed A1 > A2, ..., An,  you are to ...