码迷,mamicode.com
首页 > 其他好文 > 详细

HDU_1006_Tick and Tick

时间:2016-04-28 20:13:43      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:

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;
}

 

HDU_1006_Tick and Tick

标签:

原文地址:http://www.cnblogs.com/jasonlixuetao/p/5443931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!