这是数学题
不是模拟题
模拟的话要么精度不过,要么超时
必须算出每个临界状态,然后判断符合要求的区间,对区间的时间求和
代码如下
#include
#include
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
while(HS+1e-6
while(MS+1e-6
{
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);
}
}
神题 , 不推荐做