#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<iomanip>
using namespace std;
double d;
struct interval
{
double left;
double right;
};
interval solve(double a,double b){//解方程
//Angle<=v*t+a<=360-Angle;,并且和[0,60]取交集
interval p;
if(a>0){
p.left=(d-b)/a;
p.right=(360-d-b)/a;
}
else{
p.left=(360-d-b)/a;
p.right=(d-b)/a;
}
if(p.left< 0)p.left= 0;
if(p.right>60)p.right=60;
if(p.left>=p.right)p.left=p.right=0;
return p;
}
interval cross(interval a,interval b){
interval p;
p.left=max(a.left,b.left);
p.right=min(a.right,b.right);
if(p.left>=p.right)p.left=p.right=0;
return p;
}
double w_sec=6.0;
const double w_min=0.1;
const double w_hour=1.0/120;
double happytime(double hour,double min)
{
//const double d_sec=6*s;
const double d_min=min*6;//const double d_min=(min+s/60)*6;
const double d_hour=(hour+min/60)*30;//const double d_hour=(hour+min/60+s/3600)*30;
interval tim[3][2];
double differ_w=w_hour-w_min;
double differ_d=30*hour+min/2.0-6.0*min;
tim[0][0]=solve(differ_w,differ_d);
tim[0][1]=solve(-differ_w,-differ_d);
differ_w=w_min-w_sec;
differ_d=6*min;//differ_d=d_min-d_sec;
tim[1][0]=solve(differ_w,differ_d);
tim[1][1]=solve(-differ_w,-differ_d);
differ_w=w_hour-w_sec;
differ_d=30*hour+min/2.0;;//differ_d=d_hour-d_sec;
tim[2][0]=solve(differ_w,differ_d);
tim[2][1]=solve(-differ_w,-differ_d);
double time=0;
interval pos;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
for(int k=0;k<2;k++)
{
pos=cross(cross(tim[0][i],tim[1][j]),tim[2][k]);
time+=pos.right-pos.left;
}
}
}
return time;
}
int main()
{
while(cin>>d)
{
if(d==-1) break;
double time=0;
for(int h=0;h<12;h++)
{
for(int m=0;m<60;m++)
{
time+=happytime(h,m);
//cout<<time<<" ";
}
}
cout<<fixed<<setprecision(3)<<time*100/(60*60*12)<<endl;
}
return 0;
}
HDU1006
最新推荐文章于 2020-03-07 10:10:45 发布