时针分针秒针夹角问题

Tick and Tick

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20103    Accepted Submission(s): 5255


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<iostream>
double MAX(double a,double b,double c)
{
	double max=a;
	if(b>=max)
	max=b;
	if(c>=max)
	max=c;
	return max;
}
double MIN(double x,double y,double z)
{
	double min=x;
	if(y<=min)
	min=y;
	if(z<=min)
	min=z;
	return min;
}
double TIME=43200.000001;//一天的秒数 
//计算出各自的角速度
double hds=30,mds=360,sds=120*180;//单位是 度/小时
//计算之间的相对角速度 (角速度之差) 单位是度/分钟, 
double h_m=11.0/120,h_s=719.0/120,m_s=59.0/10; 
//由相对角速度计算每隔多长时间他们之间的夹角出现相同的情况
double  wh_m=360.0/h_m,wh_s=360.0/h_s,wm_s=360.0/m_s;
int main()
{
	double D;
	double begin,end;
	while(scanf("%lf",&D),D!=-1)
	{
		double anstime=0;
		//计算各自第一次满足条件的时间
		double sth_m=D/h_m,sth_s=D/h_s,stm_s=D/m_s;
		//计算各自第一次不能满足条件的时间
		double eth_m=(360-D)/h_m,eth_s=(360-D)/h_s,etm_s=(360-D)/m_s;
		//开始三重循环,求出每一次满足条件的开始时间和结束时间之差,并且累加起来,就可以求得总时间
		for(double st1=sth_m,et1=eth_m;et1<TIME;st1+=wh_m,et1+=wh_m)
		{
			for(double st2=sth_s,et2=eth_s;et2<TIME;st2+=wh_s,et2+=wh_s)
			{
				if(st1>et2)//h_m还没开始,h_s就结束了 
				continue;
				if(et1<st2)//h_s还没开始,h_m就结束了
				break;
				for(double st3=stm_s,et3=etm_s=etm_s;et3<TIME;st3+=wm_s,et3+=wm_s)
				{
					if(st2>et3||st1>et3)//m_s结束了,其他还没开始 
					continue; 
					if(et2<st3||et1<st3)//其他结束了,m_s还没开始 
					break;
					begin=MAX(st1,st2,st3);
					end=MIN(et1,et2,et3);
					anstime+=(end-begin);
					 
				 } 
			}
		 } 
		 printf("%.3lf\n",anstime/432);
	}
	
 } 



  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值