zoukankan      html  css  js  c++  java
  • HDU1006

    Tick and Tick

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

    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.
     
    #include<iostream>
    #include<cstdio>
    using namespace std;
    const double s_h = 719./120,s_m = 59./10,m_h =11./120;
    const double tsh=43200./719,tsm =3600./59,tmh =43200./11;
    double MAX(double a,double b,double c)
    {
        double max=a;
        if (b>max)
            max=b;
        if(c>max)
            max=c;
        return max;
    }
    double MIN(double a,double b,double c)
    {
        double min=a;
        if (b<min)
            min=b;
        if (c<min)
            min=c;
        return min;
    }
    int main()
    {
    
        double N;
        while (~scanf("%lf",&N))
        {
            if (N==-1)
                break;
            double bsm,bsh,bmh,esm,esh,emh,begin,end,sum=0;
            bsm=N/s_m;
            bsh=N/s_h;
            bmh=N/m_h;
            esm=(360-N)/s_m;
            esh=(360-N)/s_h;
            emh=(360-N)/m_h;
            for(double bt3=bsh,et3=esh;et3<=43200.000001;bt3+=tsh,et3+=tsh)
            {
                for (double bt2=bmh,et2=emh;et2<=43200.000001;bt2+=tmh,et2+=tmh)
                {
                    if (et2<bt3)
                        continue;
                    if (bt2>et3)
                        break;
                    for (double bt1=bsm,et1=esm;et1<43200.000001;bt1+=tsm,et1+=tsm)
                    {
                        if (et1<bt2||et1<bt3)
                            continue;
                        if (bt1>et2||bt1>et3)
                            break;
                        begin=MAX(bt1,bt2,bt3);
                        end=MIN(et1,et2,et3);
                        sum+=(end-begin);
                    }
                }
            }
            printf("%.3lf
    ",sum/432);
        }
        return 0;
    }
    View Code
    Sample Input
    0 120 90 -1
     
    Sample Output
    100.000 0.000 6.251
     
    1.数学题
    2.思路要清晰
    3.感谢discuss  0o恋蓝o0
  • 相关阅读:
    行为的封装
    分页功能-----》链表实现
    python入门教程链接
    作用域 属性链接 存储类型
    Codeforces Round #598 (Div. 3)
    CCPC2018-湖南全国邀请赛
    【洛谷P2494】 [SDOI2011]保密(分数规划+最小割)
    【洛谷P3329】 [ZJOI2011]最小割(最小割树)
    【BZOJ3716】[PA2014]Muzeum(贪心+网络流)
    【洛谷P4542】 [ZJOI2011]营救皮卡丘(费用流)
  • 原文地址:https://www.cnblogs.com/xfjy/p/4991307.html
Copyright © 2011-2022 走看看