模仿大牛的代码
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-8;
int sgn(double x)
{
if(fabs(x)<=eps)
return 0;
else
return x>0?1:-1;
}
double MAX(double a,double b,double c)
{
double d=a>b?a:b;
return c>d?c:d;
}
double MIN(double a,double b,double c)
{
double d=a<b?a:b;
return c<d?c:d;
}
int main()
{
double d;
double vh=1.0/120,vm=0.1,vs=6.0;//角速度
double vsm=vs-vm,vsh=vs-vh,vmh=vm-vh;//相对角速度
double tsm=360/vsm,tsh=360/vsh,tmh=360/vmh;//相对周期
double ans;
double a[5],b[5],c[5];
double l,r;//区间
while(scanf("%lf",&d)&&d!=-1)
{
ans=0;
for(a[0]=d/vsm,a[1]=(360-d)/vsm;sgn(a[1]-43200)<=0;a[0]+=tsm,a[1]+=tsm)
{
for(b[0]=d/vsh,b[1]=(360-d)/vsh;sgn(b[1]-43200)<=0;b[0]+=tsh,b[1]+=tsh)
{
if(sgn(a[1]-b[0])<=0)//筛选掉一些不可能的情况,节省时间
break;
if(sgn(a[0]-b[1])>=0)
continue;
for(c[0]=d/vmh,c[1]=(360-d)/vmh;sgn(c[1]-43200)<=0;c[0]+=tmh,c[1]+=tmh)
{
if(sgn(b[1]-c[0])<=0)
break;
if(sgn(b[0]-c[1])>=0)
continue;
l=MAX(a[0],b[0],c[0]);
r=MIN(a[1],b[1],c[1]);
if(sgn(r-l)>0)
ans+=r-l;
}
}
}
printf("%.3lf\n",ans/432.0);
}
return 0;
}