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
 
题目的意思是:输入角度D,求符合这个角度的一天中的happy时间占一天时间的百分之多少.....
happy时间是指  时针,分针,秒针三者之间的角度大小满足>=D就是happy时间....
 
思路:   一天24小时,也就是时钟转两圈。那么就求12小时的happy时间在除以12*60*60
    12小时的happy时间等于符合条件的每分钟的happy时间相加。
    接下来就是想办法求1分钟中符合条件的happy时间
    
         时针    分针    秒针
每秒角速度   1/120         1/10           6
一度所用时间      120             10             1/6
 
     假设现在的时间为h小时,m分钟,s秒。以数字12为起点。  
    则hw时针角度为:(h+m/60+s/3600)*1/120*3600  
     mw分针角度为:(m+s/60)*1/10*60
     sw秒针角度为:s*6
 
    要是happy时间就要满足下面三个条件
    D<=|hw-mw|<=360-D
    D<=|hw-sw|<=360-D
    D<=|mw-sw|<=360-D
    求得一个形式为D<=|ax+b|<=360-D   这里的x是秒
 
    就出来3个区间然后与[0.60]取交集得到h与m,m与s,h与s的三个两两指针的happy区间  最后在求这三个区间的交集就是符合条件的happy时间
 
 
代码如下:(详情  可以参考kuangbin的博客园,我也是看他的才知道的)      http://www.cnblogs.com/kuangbin/archive/2011/12/04/2275470.html
#include <stdio.h>
#include <math.h>
#include<iostream>
#include <algorithm>
using namespace std;
struct qujian
{
double l,r;
};
double D; qujian solve(double a,double b) //解方程 D<=a*x+b<=360-D ,并且和 [0,60] 取交集
{
qujian p1;
if(a>)
{
p1.l=(D-b)/a;
p1.r=(-D-b)/a;
}
else
{
p1.l=(-D-b)/a;
p1.r=(D-b)/a;
}
if(p1.l<)
p1.l=;
if(p1.r>)
p1.r=;
if(p1.l>=p1.r)
p1.l=p1.r=;
return p1;
}
qujian compare(qujian a,qujian b)
{
qujian p;
p.l=max(a.l,b.l);
p.r=min(a.r,b.r);
if(p.l>p.r)
p.l=p.r=;
return p;
} double happytime(double h,double m)
{
double a,b;
int i,j,k;
qujian s[][],p2; //解方程D<=|hh-mm|<=360-D
a=1.0/120.0-0.1; //hh=30*h+m/2+s/120;
b=*h+m/2.0-*m;
s[][]=solve(a,b);
s[][]=solve(-a,-b); a=0.1-;
b=*m;
s[][]=solve(a,b);
s[][]=solve(-a,-b); a=1.0/-;
b=*h+m/2.0;
s[][]=solve(a,b);
s[][]=solve(-a,-b); double ans=;
for(i=; i<; i++)
{
for(j=; j<; j++)
for(k=; k<; k++)
{
p2=compare(compare(s[][i],s[][j]),s[][k]);
ans+=p2.r-p2.l;
}
}
return ans;
} int main()
{
while(scanf("%lf",&D))
{
if(D==-)
break;
double h,m,ans=;
for(h=; h<; h++)
{
for(m=; m<; m++)
ans+=happytime(h,m);
}
printf("%.3lf\n",ans*100.0/(**));
}
return ;
}

HDU1006的更多相关文章

  1. HDU--1006

    题目介绍 Problem Description The three hands of the clock are rotating every second and meeting each oth ...

  2. hdu1006 Tick and Tick

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

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

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

  4. 【hdu1006】解方程

    http://acm.hdu.edu.cn/showproblem.php?pid=1006 这题坑了我好久,发现居然是一个除法变成了整除,TAT,所以建议在写较长的运算表达式的时候出现了除法尽量加个 ...

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

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

随机推荐

  1. 发几个Flex的学习资源

    书籍: 目前在看两本 <Essential.ActionScript.3.0> <Flex 4 In Action> 还有两本当手册翻阅,非常喜欢Cookbook这种题材的书, ...

  2. ORA-01810: 格式代码出现两次

    今天在修改SQL语句的时候遇到这个小问题,提示的还是比较明显的,当然解决之道我是从百度上摘取的! 错误语句段:AND V.UPLOAD_DATE <=TO_DATE ('2013-11-11 2 ...

  3. MacOSX和Windows 8的完美融合

    MacOSX和Windows8的完美融合 一般情况下我们要在MACOS系统下运行Windows软件怎么办呢?一种方法我们可以装CrossOver这款软件,然后在configuration->in ...

  4. 如何在MAC机器中实现移动设备WiFI上网(没有专门的无线路由器的情况)

    在很多办公室甚至家中都有无线路由器以方便通过WIFI信号上网.如果没有无线路由器,如何让多个移动智能终端同时上网呢?如果你是Windows用户那么可以选择wifi共享精灵来解决,如果你拥有MAC机器, ...

  5. 【缓存】EF4ProviderWrappers

    在Kooboo中使用了Entity Framework作为持久化框架,但由于EF1.0并没有提供完整缓存解决方案,一直以来都在为数据缓存而烦脑,在没有找到合适解决方案的情况下,采取了临时的解决办法:直 ...

  6. JS常用的设计模式(16)—— 享元模式

    享元模式主要用来减少程序所需的对象个数. 有一个例子, 我们这边的前端同学几乎人手一本<JavaScript权威指南>. 从省钱的角度讲, 大约三本就够了. 放在部门的书柜里, 谁需要看的 ...

  7. SQL server 性能调优

    转自: http://www.cnblogs.com/MR_ke/archive/2010/08/25/1807856.html sql 2005性能调优 SQL Server在运行一段时间,随着数据 ...

  8. 在xargx命令中如何使用重定向

    ls *.txt | xargs -i -n 1 sh -c "cut -f 1-3 {} > ../{}"即可

  9. Bypass pattern lock on Sony Xperia Z2 and backup all data

    Yesterday she came to me with a Sony Xperia Z2 D6503. Guess what? She forgot the pattern so she coul ...

  10. Android IOS WebRTC 音视频开发总结(三三)-- Periscope介绍

    本文主要介绍Periscope,文章来自博客园RTC.Blacker,支持原创,转载请说明出处. 可能国内很多人没听说过Periscope,这可是现在Twitter上很火的一个APP,先看看人家自己是 ...