程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Tick and Tick------HDOJ杭電(解釋不了,直接看代碼)

Tick and Tick------HDOJ杭電(解釋不了,直接看代碼)

編輯:C++入門知識

Tick and Tick------HDOJ杭電(解釋不了,直接看代碼)


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
#include 
#include 
using namespace std;
#define vs 6.
#define vm 1./double(10)
#define vh 1./double(120)

int main()
{
    double D;
    double T[3]= {(360./(vm-vh)),(360./(vs-vm)),(360./(vs-vh))}; ///時分 分秒 時秒 的相對周期
    while(cin>>D && D!=-1)
    {
        double HS[3]= {(D/360.)*T[0],(D/360.)*T[1],(D/360.)*T[2]}; ///存儲每對針的開始Happy時間
        double HE[3]= {(360.-D)/360.*T[0],((360.-D)/360.*T[1]),((360.-D)/360.*T[2])}; ///存儲每對針的結束Happy時間
        double happyTime=0.,nextHS=HS[0],nextHE=min(HE[1],HE[2]);
        while(HS[1]<43200-(D/360.)*T[0] && HS[2]<43200-(D/360.)*T[0])
        {
            nextHS= max(HS[0],max(HS[1],HS[2]));
            nextHE= min(HE[0],min(HE[1],HE[2]));
            happyTime += (nextHE-nextHS)>0.?nextHE-nextHS:0.;
            for(int i=0; i<3; i++)
            {
                HS[i]+=(nextHE-HE[i]<0.?HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.;
                HE[i]+=(nextHE-HE[i]<0.?HE[i]-nextHE:nextHE-HE[i])<1e-15?T[i]:0.;
            }
        }
        double result= happyTime/432.;
        cout<
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved