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
 
 
  1. #include<stdio.h>
  2. /*-----------------------------------------------
  3. double取最大最小函数
  4. */
  5. double max(double a,double b){
  6. if(a>b)return a;
  7. return b;
  8. }
  9. double min(double a,double b){
  10. if(a>b)return b;
  11. return a;
  12. }//---------------------------------------------
  13. /*
  14. 集合结构体
  15. */
  16. struct set{
  17. double a,double b;
  18. };//集合区间的左右
  19. double d;
  20. /*---------------------------------------------
  21. 求d<=ax+b<360-d的解
  22. */
  23. struct set sloveset(double a,double b){
  24. struct set seta;
  25. if(a>){
  26. seta.a=(d-b)/a;
  27. seta.b=(-d-b)/a;
  28. }
  29. else{
  30. seta.b=(d-b)/a;
  31. seta.a=(-d-b)/a;
  32. }
  33. if(seta.a<) seta.a=;
  34. if(seta.b>) seta.b=;
  35. if(seta.a>=seta.b) seta.a=seta.b=;//之前这句放到了if(seta.a<0)if(seta.b>60)前面了
  36. return seta; //结果seta.b变成了负的怀疑是seta.b太大了冒了不知对错
  37. }
  38. /*---------------------------------------------
  39. 给2个集合求交集
  40. */
  41. struct set intersection(struct set a,struct set b){
  42. struct set p;
  43. p.a=a.a>b.a ?a.a:b.a;
  44. p.b=a.b<b.b ?a.b:b.b;
  45. if(p.a>p.b) p.a=p.b=;
  46. return p;
  47. }//////////////////////////////////////////////////////////
  48. int main(){
  49. int h,m,i,j,k;
  50. double a1,b1,a2,b2,a3,b3,time;
  51. struct set answer[][],ensemble;
  52. while(scanf("%lf",&d)&&d!=-){
  53. time=;
  54. for(h=;h<;h++){
  55. for(m=;m<;m++){
  56. b1=6.0*m;a1=-5.9;
  57. b2=*h+0.5*m;a2=1.0/-6.0;
  58. b3=*h+(0.5-)*m;a3=(1.0/)-0.1;
  59. /*求3个绝对值不等式的解集 存到answer中answer[0][0] answer[0][1]要取并集剩下两个也是 */
  60. answer[][]=sloveset(a1,b1); answer[][]=sloveset(-a1,-b1);
  61. answer[][]=sloveset(a2,b2); answer[][]=sloveset(-a2,-b2);
  62. answer[][]=sloveset(a3,b3); answer[][]=sloveset(-a3,-b3);
  63. // 取过交集后,需要将3个式子的结果取并集 所以采用下面的方法
  64. for(i=;i<;i++){
  65. for(j=;j<;j++){
  66. for(k=;k<;k++){
  67. ensemble=intersection(intersection(answer[][i],answer[][j]),answer[][k]);
  68. time+=ensemble.b-ensemble.a;
  69. }
  70. }
  71. }
  72. }
  73. }
  74. time=time*100.0/(*);
  75. printf("%.3lf\n",time);
  76. }
  77. return ;
  78. }
 

[ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]的更多相关文章

  1. HDU 1006 Tick and Tick(时钟,分钟,秒钟角度问题)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1006 Tick and Tick Time Limit: 2000/1000 MS (Java/Oth ...

  2. HDU 1006 Tick and Tick 时钟指针问题

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

  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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  6. hdu1006 Tick and Tick

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

  7. HDU 1006 [Tick Tick]时钟问题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题目大意:钟表有时.分.秒3根指针.当任意两根指针间夹角大于等于n°时,就说他们是happy的, ...

  8. HDU 1006 Tick and Tick 解不等式解法

    一開始思考的时候认为好难的题目,由于感觉非常多情况.不知道从何入手. 想通了就不难了. 能够转化为一个利用速度建立不等式.然后解不等式的问题. 建立速度,路程,时间的模型例如以下: /******** ...

  9. 1006 Tick and Tick

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1006 题意: 24小时中,三个指针之间超过某个度数的时间占所有时间的百分比是多少. 思路:主要是物理和数学 ...

随机推荐

  1. 使用UUID方法生成全球唯一标识

    需要生成唯一字符串,如生成应用标识等,可以直接用java.util.UUID类实现. UUID(Universally Unique Identifier)全局唯一标识符,是指在一台机器上生成的数字, ...

  2. Python oct() 函数

    Python oct() 函数  Python 内置函数 描述 oct() 函数将一个整数转换成8进制字符串. 语法 oct 语法: oct(x) 参数说明: x -- 整数. 返回值 返回8进制字符 ...

  3. Find Peak Element(ARRAY - Devide-and-Conquer)

    QUESTION A peak element is an element that is greater than its neighbors. Given an input array where ...

  4. 在UNITY中按钮的高亮用POINT灯实现,效果别具一番风味

    在UNITY中按钮的高亮用POINT灯实现,效果别具一番风味

  5. Treasures and Vikings(两次搜索)

    Treasures and Vikings https://www.luogu.org/problemnew/show/P4668 题意翻译 你有一张藏宝图,藏宝图可视为 N×MN×M 的网格.每个格 ...

  6. CSS中的各种width(宽度)

    一 window对象的innerWidth.outerWidth innerWidth是可用区域的宽度(内容区 + 滚动条) outerWidth是浏览器窗口的宽度(可用区域的宽度+审查元素区域的宽度 ...

  7. 【校招面试 之 C/C++】第29题 C/C++ 关键字extern

    1.extern "C" extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示 ...

  8. actionBar_Tab导航

    actionBar配合碎片使用  初始化actionBar要注意设置actionbar的导航模式 package com.qf.actionbar04_tab; import java.io.File ...

  9. php 的 PHPExcel1.8.0 使用教程

    PHPExcel是用来操作Office Excel文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格.   一.下载PHPExcel http: ...

  10. win7系统administrator用户提示没有管理员权限,造装驱动安装错误,软件无法使用

    警告1909.无法创建快捷方式 最近使用windows 7 32位安装软件,好多都失败.出现以上类似错误. 解决方法:在系统盘(C:)右键属性“安全”选项卡--“编辑”,添加“Everyone”设置为 ...