• [ACM_模拟] HDU 1006 Tick and Tick [时钟间隔角度问题]


    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>0){
    26         seta.a=(d-b)/a;
    27         seta.b=(360-d-b)/a;
    28     }
    29     else{
    30         seta.b=(d-b)/a;
    31         seta.a=(360-d-b)/a;
    32     }
    33     if(seta.a<0) seta.a=0;
    34     if(seta.b>60) seta.b=60;
    35     if(seta.a>=seta.b) seta.a=seta.b=0;//之前这句放到了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=0;
    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[3][2],ensemble;
    52     while(scanf("%lf",&d)&&d!=-1){
    53         time=0;
    54         for(h=0;h<12;h++){
    55             for(m=0;m<60;m++){
    56                 b1=6.0*m;a1=-5.9;
    57                 b2=30*h+0.5*m;a2=1.0/120-6.0;
    58                 b3=30*h+(0.5-6)*m;a3=(1.0/120)-0.1;
    59                 /*求3个绝对值不等式的解集 存到answer中answer[0][0] answer[0][1]要取并集剩下两个也是 */
    60                 answer[0][0]=sloveset(a1,b1);              answer[0][1]=sloveset(-a1,-b1);
    61                 answer[1][0]=sloveset(a2,b2);              answer[1][1]=sloveset(-a2,-b2);
    62                 answer[2][0]=sloveset(a3,b3);              answer[2][1]=sloveset(-a3,-b3);
    63                 // 取过交集后,需要将3个式子的结果取并集 所以采用下面的方法
    64                 for(i=0;i<2;i++){
    65                     for(j=0;j<2;j++){
    66                         for(k=0;k<2;k++){
    67                             ensemble=intersection(intersection(answer[0][i],answer[1][j]),answer[2][k]);
    68                             time+=ensemble.b-ensemble.a; 
    69                         }
    70                     } 
    71                 }
    72             }
    73         }
    74         time=time*100.0/(12*3600);
    75         printf("%.3lf
    ",time);
    76     }
    77     return 0;
    78 }
     
  • 相关阅读:
    人脸识别员工考勤系统
    栈和队列
    线性表
    C语言博客作业02--循环结构
    课程设计-个人博客
    C博客作业02--循环结构
    博客作业--函数
    c博客作业
    联系方式
    专业特长
  • 原文地址:https://www.cnblogs.com/zjutlitao/p/3690337.html
Copyright © 2020-2023  润新知