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
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include<iostream>
  4. #include <algorithm>
  5. using namespace std;
  6. struct qujian
  7. {
  8. double l,r;
  9. };
  10. double D;
  11.  
  12. qujian solve(double a,double b) //解方程 D<=a*x+b<=360-D ,并且和 [0,60] 取交集
  13. {
  14. qujian p1;
  15. if(a>)
  16. {
  17. p1.l=(D-b)/a;
  18. p1.r=(-D-b)/a;
  19. }
  20. else
  21. {
  22. p1.l=(-D-b)/a;
  23. p1.r=(D-b)/a;
  24. }
  25. if(p1.l<)
  26. p1.l=;
  27. if(p1.r>)
  28. p1.r=;
  29. if(p1.l>=p1.r)
  30. p1.l=p1.r=;
  31. return p1;
  32. }
  33. qujian compare(qujian a,qujian b)
  34. {
  35. qujian p;
  36. p.l=max(a.l,b.l);
  37. p.r=min(a.r,b.r);
  38. if(p.l>p.r)
  39. p.l=p.r=;
  40. return p;
  41. }
  42.  
  43. double happytime(double h,double m)
  44. {
  45. double a,b;
  46. int i,j,k;
  47. qujian s[][],p2; //解方程D<=|hh-mm|<=360-D
  48. a=1.0/120.0-0.1; //hh=30*h+m/2+s/120;
  49. b=*h+m/2.0-*m;
  50. s[][]=solve(a,b);
  51. s[][]=solve(-a,-b);
  52.  
  53. a=0.1-;
  54. b=*m;
  55. s[][]=solve(a,b);
  56. s[][]=solve(-a,-b);
  57.  
  58. a=1.0/-;
  59. b=*h+m/2.0;
  60. s[][]=solve(a,b);
  61. s[][]=solve(-a,-b);
  62.  
  63. double ans=;
  64. for(i=; i<; i++)
  65. {
  66. for(j=; j<; j++)
  67. for(k=; k<; k++)
  68. {
  69. p2=compare(compare(s[][i],s[][j]),s[][k]);
  70. ans+=p2.r-p2.l;
  71. }
  72. }
  73. return ans;
  74. }
  75.  
  76. int main()
  77. {
  78. while(scanf("%lf",&D))
  79. {
  80. if(D==-)
  81. break;
  82. double h,m,ans=;
  83. for(h=; h<; h++)
  84. {
  85. for(m=; m<; m++)
  86. ans+=happytime(h,m);
  87. }
  88. printf("%.3lf\n",ans*100.0/(**));
  89. }
  90. return ;
  91. }

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. 【Unity Shaders】学习笔记——SurfaceShader(十一)光照模型

    [Unity Shaders]学习笔记——SurfaceShader(十一)光照模型 转载请注明出处:http://www.cnblogs.com/-867259206/p/5664792.html ...

  2. 《FPGA全程进阶---实战演练》第二十一章 电源常用类型:LDO和 DCDC

    高速电路中的电源设计 高速电路中的电源设计大概分为两种,一种是集总式架构,一种是分布式架构.集总式架构就是由一个电源输入,然后生成多种所需要的电压.如图1所示.这种架构会增加多个DC/DC模块,这样成 ...

  3. Solum入门知识(编辑中)

    概要 参考:https://wiki.openstack.org/wiki/Solum An OpenStack project designed to make cloud services eas ...

  4. 【LeetCode】16. 3Sum Closest

    题目: Given an array S of n integers, find three integers in S such that the sum is closest to a given ...

  5. OC项目中使用Swift

    1.在OC工程中新建 Swift 文件,会提示的是否创建一个桥接文件,创建不创建都无所谓,这个桥接文件主要是用来包含OC头文件的,主要用于Swift中使用OC         2.在Person.sw ...

  6. 学习练习 java 线程

    package com.hanqi.xc; import java.util.*; public class lianxi extends Thread { public void run() { c ...

  7. CSS长度单位

    罗列了CSS中常用的长度单位及比较 单位 含义 em 相对于父元素的字体大小 ex 相对于小写字母"x"的高度 rem 相对于根元素字体大小 px 相对于屏幕分辨率而不是视窗大小: ...

  8. projecteuler Sum square difference

    The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of ...

  9. 如何使VS2008 调试网站的根目录和IIS调试的一致?

    用VS2008做asp.net网站调试时,经常会多出来一个目录,如http://localhost:1234/Foo/ , 由于一些图片的路径问题,我们不需要最后的/Foo/目录,而是像IIS调试那样 ...

  10. [视频]物联网应用-ARM mbed-来至MultiTech Systems的解决方案

    ARM公司面向物联网及可穿戴市场,近期可谓是动作频频,先是发布了专为物联网及可穿戴领域而生的Cortex-M7架构,接着又发布了mbed物联网操作系统.意图在物联网领域构筑一套坚不可摧的生态系统. 这 ...