杭电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
这是数学
不是模拟题
模拟的话要么精度不过,要么超时
必须算出每个临界状态,然后判断符合要求的区间,对区间的时间求和
代码如下
#include <stdio.h>
#include <stdlib.h>

double D;
int H,M;
double S, Total;
int signal;
double minimum;
double maximum;

void get_next()
{
double HM,HS,MS;
double HL,ML,SL;
double t1,t2,t3;
SL = 6*S;
ML = 6*(M+S/60);
HL = 30*(H+M/60.0+S/3600);
HM = ML - HL;
HS = SL - HL;
MS = SL - ML;
while(HM+1e-6>=D) HM -= 360;
while(HM+1e-6<D-360) HM += 360;
while(HS+1e-6>=D) HS -= 360;
while(HS+1e-6<D-360) HS += 360;
while(MS+1e-6>=D) MS -= 360;
while(MS+1e-6<D-360) MS += 360;
if(HM>=-D||HS+1e-10>=-D||MS+1e-10>=-D)
{
signal = 0;
t1 = (D - HM)/(1.0/10 - 1.0/120);
t2 = (D - HS)/(6-1.0/120);
t3 = (D - MS)/(6-1.0/10);
minimum = 0;
if(HM>=-D) minimum = minimum > t1? minimum : t1;
if(HS+1e-6>=-D) minimum = minimum > t2? minimum : t2;
if(MS+1e-6>液陆=-D) minimum = minimum > t3? minimum : t3;
S += minimum;
while(S>=60)
{
S-=60;
M++;
}
while(M>=60)
{
M-=60;
H++;
}
return;
}
else
{
signal = 1;
t1 = (-D - HM)/(1.0/10 - 1.0/120);
t2 = (-D - HS)/盯埋哪(6-1.0/120);
t3 = (-D - MS)/(6-1.0/10);
maximum = 100000;
maximum = maximum < t1? maximum : t1;
maximum = maximum < t2? maximum : t2;
maximum = maximum < t3? maximum : t3;
S += maximum;
while(S>=60)
{
S-=60;
M++;
}
while(M>=60)
{
M-=60;
H++;
}
return;
}
}

int main()
{
while(scanf("%lf",&D)&&D!=-1)
{
if(D==0)
{
printf("100.000\n"凯码);
continue;
}
if(D>=120)
{
printf("0.000\n");
continue;
}
H = M = 0;
S = 0;
Total = 0;
while(1)
{
get_next();
if(H>=12) break;
if(signal) Total += maximum;
}
printf("%.3lf\n",Total/432);
}
}
神题 , 不推荐做