zoukankan      html  css  js  c++  java
  • hdu 1006 Tick and Tick

    Tick and Tick

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 19764    Accepted Submission(s): 5164


    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 <iostream>
     2 #include <stdio.h>
     3 #include <algorithm>
     4 #include <string.h>
     5 #include <cmath>
     6 using namespace std;
     7 double D;
     8 double sum;
     9 struct node
    10 {
    11     double l,r;
    12 };
    13 node ans[3][2];
    14 node solve(double a,double b)
    15 {
    16     node qu;
    17     if(a>0)
    18     {
    19         qu.l=(D-b)/a;
    20         qu.r=(360-D-b)/a;
    21     }
    22     else
    23     {
    24         qu.l=(360-D-b)/a;
    25         qu.r=(D-b)/a;
    26     }
    27     if(qu.l<0) qu.l=0;
    28     if(qu.r>60) qu.r=60;
    29     if(qu.l>=qu.r) { qu.l=qu.r=0;}
    30     return qu;
    31 }
    32 node mer_g(node a,node b)
    33 {
    34     node q;
    35     q.l=max(a.l,b.l);
    36     q.r=min(a.r,b.r);
    37     if(q.l>q.r) q.l=q.r=0;
    38     return q;
    39 }
    40 int main()
    41 {
    42     int h,m;
    43     int i,j,k;
    44     double a1,a2,a3,b1,b2,b3;
    45     while(scanf("%lf",&D),D!=-1)
    46     {
    47         sum=0;
    48         node qu;
    49        for(h=0;h<12;h++)
    50          for(m=0;m<60;m++)
    51             {
    52                b1=m*6;        a1=-5.9;
    53                b2=30*h+(0.5-6)*m; a2=1.0/120-0.1;
    54                b3=30*h+0.5*m; a3=1.0/120-6;
    55                ans[0][0]=solve(a1,b1);ans[0][1]=solve(-a1,-b1);
    56                ans[1][0]=solve(a2,b2);ans[1][1]=solve(-a2,-b2);
    57                ans[2][0]=solve(a3,b3);ans[2][1]=solve(-a3,-b3);
    58               for(i=0;i<2;i++)
    59                for(j=0;j<2;j++)
    60                 for(k=0;k<2;k++)
    61                  {
    62                    qu=mer_g(mer_g(ans[0][i],ans[1][j]),ans[2][k]);
    63                    sum+=qu.r-qu.l;
    64                  }
    65             }
    66       printf("%.3lf
    ",sum*100/43200);
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    C语言I博客作业09
    C语言I博客作业08
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
  • 原文地址:https://www.cnblogs.com/52why/p/7478091.html
Copyright © 2011-2022 走看看