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\n",res/432);
    }
    return 0;
}

 

posted on 2016-04-28 19:24  JASONlee3  阅读(322)  评论(0编辑  收藏  举报

导航