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

由于枚举的是重合到重合,所以先求出时针和分针,分针和秒针,时针和秒针之间的相对角速度和再重合周期。通过相对角速度hm,hs,ms,我们可以求出从重合到分离n度所需的时间n/hm,n/hs,n/ms,以及到再重合前n度所需的时间(360-n)/hm,(360-n)/hs,(360-n)/ms。每次枚举,i,j,k表示hm,hs,ms各自重合的时间,那么p=max(i+n/hm,j+n/hs,k+ms)就是最早的三针分离n度的时间;q=min(i+(360-n)/hm,j+(360-n)/hs,k+(360-n)/ms)就是最晚三针合并到n度的时间,那么时间区间[p,q]就是符合条件的时间段。

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<map>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<sstream>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include <ctype.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; typedef long long ll;
//const int maxn=10005;
const int INF=0x3f3f3f3f;
const int maxn=12*60*60;
double hm,hs,ms,T_hm,T_hs,T_ms;
void init()
{
double h,m,s;//角速度(等于走过的弧长除以时间,都按走一圈算)
h=1.0/120;
m=1.0/10;
s=6;
hm=m-h;
hs=s-h;
ms=s-m;//表示两个针分离的速度
T_hm=360/hm;//表示时针和分针从重合到再次重合所花的时间,下面同理
T_hs=360/hs;
T_ms=360/ms;
//printf("%.3lf %.3lf %.3lf\n",T_hm*11,T_hs*719,T_ms*59);
}
double Max(double a,double b,double c)
{
return max(max(a,b),c);
}
double Min(double a,double b,double c)
{
return min(min(a,b),c);
}
int main()
{
init();
double n;
while(scanf("%lf",&n)!=EOF)
{
if(n<0)break;
double i,j,k,a[6],p,q,ans=0;
//两针分离到n所需的时间
a[0]=n/hm;
a[1]=n/hs;
a[2]=n/ms;
//两针合并到n所需的时间,等价于两针分离了360-n
a[3]=(360-n)/hm;
a[4]=(360-n)/hs;
a[5]=(360-n)/ms;
//每次所有的针从有重合到再次有重合至多有一段连续的段符合三针分离度大于n。
for(i=0; i<=1.0*maxn; i+=T_hm)
{
for(j=0; j<=1.0*maxn; j+=T_hs)
{
if(j+a[1]>i+a[3])break;//p>=j+a[1]&&q<=i+a[3]=>p>q=>无效
if(i+a[0]>j+a[4])continue;//与上同理
for(k=0; k<=1.0*maxn; k+=T_ms)
{
if(k+a[2]>i+a[3]||k+a[2]>j+a[4])break;
if(i+a[0]>k+a[5]||j+a[1]>k+a[5])continue;
p=Max(i+a[0],j+a[1],k+a[2]);//在这三个时间段刚好完成分离n度,所以取最大值才能保证全都分离n以上
q=Min(i+a[3],j+a[4],k+a[5]);//在这三个时间段刚好完成合并n度,所以取最小值才能保证全都未合并到n以内
if(q>p)
ans+=q-p;
}
}
}
printf("%.3lf\n",100.0*ans/maxn);
}
return 0;
}

hdu1006 Tick and Tick (数学题 借鉴了大神的博客)的更多相关文章

  1. 想要进步,就要阅读大神的博客,再推荐一波springmvc映射路径之url的action请求

    http://www.cnblogs.com/liukemng/p/3726897.html

  2. 大神的博客地址liferay

    http://www.huqiwen.com/category/technology-share/liferay/

  3. 红黑树-算法大神的博客-以及java多线程酷炫的知识

    http://www.cnblogs.com/skywang12345/p/3245399.html 解释第5条:从 ->根节点(或者任意个结点)到->所有的末端节点的路径中 ->黑 ...

  4. linux嵌入式大神的博客文章---持续更新中

    linux kernel子系统相关博客:http://www.wowotech.net/ 经典博文: http://blog.csdn.net/zqixiao_09 http://blog.china ...

  5. 理解z-index和css中的层叠顺序问题(大神技术博的读后感?)

    一直对 z-index不太理解,今天看到了大神的博客...http://www.zhangxinxu.com/wordpress/tag/z-index/ 1.层叠上下文:是一个名词!是一个性质!此时 ...

  6. 2011年度十大杰出IT博客获奖感言

        2011年度十大杰出IT博客获奖感言 在各位评委.网友的支持下,我的博客从前50名中脱颖而出跻身10强,得到这个消息之后心中充满了喜悦.在这里要感谢51CTO为大家提供这样一个良好的展示平台. ...

  7. 各大IT技术博客排行榜

    cnblogs 积分排名前3000名 http://www.cnblogs.com/ 左侧有推荐博客排行 cppblog http://www.cppblog.com/AllBloggers.aspx ...

  8. 大数据系列博客之 --- 深入简出 Shell 脚本语言(高级篇)

    首先声明,此系列shell系列博客分为四篇发布,分别是: 基础篇:https://www.cnblogs.com/lsy131479/p/9914747.html 提升篇:https://www.cn ...

  9. 大数据系列博客之 --- 深入简出 Shell 脚本语言(提升篇)

    首先声明,此系列shell系列博客分为四篇发布,分别是: 基础篇:https://www.cnblogs.com/lsy131479/p/9914747.html 提升篇:https://www.cn ...

随机推荐

  1. loj515 「LibreOJ β Round #2」贪心只能过样例

    传送门:https://loj.ac/problem/515 [题解] 容易发现S最大到1000000. 于是我们有一个$O(n^2*S)$的dp做法. 容易发现可以被bitset优化. 于是复杂度就 ...

  2. Bzoj4710 [Jsoi2011]分特产

    Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 96  Solved: 62[Submit][Status][Discuss] Description ...

  3. 【BZOJ】2196: [Usaco2011 Mar]Brownie Slicing

    [题意]给定n*m的数字矩阵,要求横着切A-1刀,对每块再分别竖着切B-1刀,是最小子矩阵最大. [算法]二分+贪心 [题解]还记得提高组2015跳石头吗?这道题做法一致,只不过拓展到二维而已. 二分 ...

  4. 【洛谷 P1707】 刷题比赛 (矩阵加速)

    题目连接 很久没写矩阵加速了,复习一下,没想到是一道小毒瘤题. 状态矩阵\(a[k],b[k],c[k],a[k+1],b[k+1],c[k+1],k,k^2,w^k,z^k,1\) 转移矩阵 0, ...

  5. JqGrid自定义(图片)列

    $("#gridTable").jqGrid({ //...其它属性 colModel: [ //...其它列 { name: , align: "center" ...

  6. poj 1837 Balance(背包)

    题目链接:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS   Memory Limit: 30000K Total Submissi ...

  7. 在AndroidStudio中导入开源库 或者jar

    方法一: 先点击Androidstudio中的Project Structure,如图 图1 到如下界面 图2 然后点击+号 图3 选择Library dependency 图4 输入你要的jar包, ...

  8. linux c 执行新程序

    学习进程时,linu c上说新开的进程一般要执行另外一个程序,同时与父进程执行同一个程序没有意义 如下是如何执行一个新的程序 使用exec函数簇 exec函数簇包含如下函数

  9. 终于解决了Linux下运行OCCI程序一直报Error while trying to retrieve text for error ORA-01804错误

    终于解决了Linux下运行OCCI程序一直报Error while trying to retrieve text for error ORA-01804错误 http://blog.csdn.net ...

  10. sicily 1036. Crypto Columns

    Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description The columnar encryption scheme scram ...