杭电acm1006求解答Tick and TickTime Limit:2000/1000 MS (Java/Others) Memory Limit:65536/32768 K (Java/Others)Total Submission(s):3382 Accepted Submission(s):876Problem DescriptionThe three hands of the clock are rotating every second and meeting
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/18 07:37:26
杭电acm1006求解答Tick and TickTime Limit:2000/1000 MS (Java/Others) Memory Limit:65536/32768 K (Java/Others)Total Submission(s):3382 Accepted Submission(s):876Problem DescriptionThe three hands of the clock are rotating every second and meeting
杭电acm1006求解答
Tick and Tick
Time Limit:2000/1000 MS (Java/Others) Memory Limit:65536/32768 K (Java/Others)
Total Submission(s):3382 Accepted Submission(s):876
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
杭电acm1006求解答Tick and TickTime Limit:2000/1000 MS (Java/Others) Memory Limit:65536/32768 K (Java/Others)Total Submission(s):3382 Accepted Submission(s):876Problem DescriptionThe three hands of the clock are rotating every second and meeting
这是数学题
不是模拟题
模拟的话要么精度不过,要么超时
必须算出每个临界状态,然后判断符合要求的区间,对区间的时间求和
代码如下
#include
#include
double D;
int H,M;
double S, Total;
int signal;
double minimum;
double maximum;
void get_next()
{
\x09double HM,HS,MS;
\x09double HL,ML,SL;
\x09double t1,t2,t3;
\x09SL = 6*S;
\x09ML = 6*(M+S/60);
\x09HL = 30*(H+M/60.0+S/3600);
\x09HM = ML - HL;
\x09HS = SL - HL;
\x09MS = SL - ML;
\x09while(HM+1e-6>=D) HM -= 360;
\x09while(HM+1e-6=D) HS -= 360;
\x09while(HS+1e-6=D) MS -= 360;
\x09while(MS+1e-6=-D||HS+1e-10>=-D||MS+1e-10>=-D)
\x09{
\x09\x09signal = 0;
\x09\x09t1 = (D - HM)/(1.0/10 - 1.0/120);
\x09\x09t2 = (D - HS)/(6-1.0/120);
\x09\x09t3 = (D - MS)/(6-1.0/10);
\x09\x09minimum = 0;
\x09\x09if(HM>=-D) minimum = minimum > t1? minimum : t1;
\x09\x09if(HS+1e-6>=-D) minimum = minimum > t2? minimum : t2;
\x09\x09if(MS+1e-6>=-D) minimum = minimum > t3? minimum : t3;
\x09\x09S += minimum;
\x09\x09while(S>=60)
\x09\x09{
\x09\x09\x09S-=60;
\x09\x09\x09M++;
\x09\x09}
\x09\x09while(M>=60)
\x09\x09{
\x09\x09\x09M-=60;
\x09\x09\x09H++;
\x09\x09}
\x09\x09return;
\x09}
\x09else
\x09{
\x09\x09signal = 1;
\x09\x09t1 = (-D - HM)/(1.0/10 - 1.0/120);
\x09\x09t2 = (-D - HS)/(6-1.0/120);
\x09\x09t3 = (-D - MS)/(6-1.0/10);
\x09\x09maximum = 100000;
\x09\x09maximum = maximum < t1? maximum : t1;
\x09\x09maximum = maximum < t2? maximum : t2;
\x09\x09maximum = maximum < t3? maximum : t3;
\x09\x09S += maximum;
\x09\x09while(S>=60)
\x09\x09{
\x09\x09\x09S-=60;
\x09\x09\x09M++;
\x09\x09}
\x09\x09while(M>=60)
\x09\x09{
\x09\x09\x09M-=60;
\x09\x09\x09H++;
\x09\x09}
\x09\x09return;
\x09}
}
int main()
{
\x09while(scanf("%lf",&D)&&D!=-1)
\x09{
\x09\x09if(D==0)
\x09\x09{
\x09\x09\x09printf("100.000\n");
\x09\x09\x09continue;
\x09\x09}
\x09\x09if(D>=120)
\x09\x09{
\x09\x09\x09printf("0.000\n");
\x09\x09\x09continue;
\x09\x09}
\x09\x09H = M = 0;
\x09\x09S = 0;
\x09\x09Total = 0;
\x09\x09while(1)
\x09\x09{
\x09\x09\x09get_next();
\x09\x09\x09if(H>=12) break;
\x09\x09\x09if(signal) Total += maximum;
\x09\x09}
\x09\x09printf("%.3lf\n",Total/432);
\x09}
}