• 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): 16633    Accepted Submission(s): 4059


    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
     
    Author
    PAN, Minghao
     
    Source
     
    之前一秒一秒离散地模拟,一直wa。
    最后看了题解,是看作连续来做。
    由角速度求出相对角速度,再求出每两根针的周期(经过多久再次重合)。然后求12个小时内每两根针(3组)每个周期happy time的交集的和。
     
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    
    const double h_m=11.0/120,h_s=719.0/120,m_s=59.0/10;    //相对角速度
    const double Th_m=43200.0/11,Th_s=43200.0/719,Tm_s=3600.0/59;  //周期
    
    int main()
    {
        double d;
        while(scanf("%lf",&d)!=EOF&&d>=0)
        {
            ///d/h_m
            double sh_m=d/h_m;
            double eh_m=(360.0-d)/h_m;
            double sh_s=d/h_s;
            double eh_s=(360.0-d)/h_s;
            double sm_s=d/m_s;
            double em_s=(360.0-d)/m_s;
            double s1,e1,s2,e2,s3,e3,s4,e4,res=0;
            for(s1=sh_m,e1=eh_m;e1<=43200.000001;s1+=Th_m,e1+=Th_m)
            {
                for(s2=sh_s,e2=eh_s;e2<=43200.000001;s2+=Th_s,e2+=Th_s)
                {
                    if(e1<=s2)
                        break;
                    if(e2<=s1)
                        continue;
                    for(s3=sm_s,e3=em_s;e3<=43200.000001;s3+=Tm_s,e3+=Tm_s)
                    {
                        if(s3>=e2||s3>=e1)
                            break;
                        if(e3<=s2||e3<=s1)
                            continue;
                        s4=max(s1,max(s2,s3));
                        e4=min(e1,min(e2,e3));
                        res+=(e4-s4);
                    }
                }
            }
            printf("%.3lf
    ",res/432);
        }
        return 0;
    }
  • 相关阅读:
    【leetcode】1415. The k-th Lexicographical String of All Happy Strings of Length n
    【leetcode】1413. Minimum Value to Get Positive Step by Step Sum
    【leetcode】1410. HTML Entity Parser
    【leetcode】1409. Queries on a Permutation With Key
    1, 2, and 4 symbols per clock中数据排列
    RGB转换成YCbCr
    RAW转换成RGB
    ROM的一种写法
    IP之ALTIOBUF仿真
    IP之ALTDDIO_in仿真
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5443931.html
Copyright © 2020-2023  润新知