HDU1006

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值