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
  • 相关阅读:
    用webservice实现的一个天气预报程序
    让VS.net2005手机模拟器上网
    EVC4.0 PPC2003 Emulator 转中文版
    BSTR转CString
    在pocket pc 2003上播放声音
    VC++.net 2005 SmartDevice 屏幕转向
    c#.net2005 调用evc4.0生成的dll文件
    Json
    adb 命令模拟按键事件
    bat 截取字符
  • 原文地址:https://www.cnblogs.com/xfjy/p/4991307.html
Copyright © 2011-2022 走看看