hdoj1006 Tick and Tick(数学问题,解不等式,求并集)

来源:http://acm.hdu.edu.cn/showproblem.php?pid=1006

看秒针的转动,一分钟一分钟的算

#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;
struct range//取值范围 
{
	double l,r;
};
double d;
range work(double a,double b)//求 d<=ax+b<360-d 的解,x为秒。 
{
	range temp;
	if(a>0)
	{
		temp.l=(d-b)/a;
		temp.r=(360-d-b)/a;
	}
	else
	{
		temp.l=(360-d-b)/a;
		temp.r=(d-b)/a;
	}
	if(temp.l<0)temp.l=0;
	if(temp.r>60)temp.r=60;
	if(temp.l>=temp.r)temp.r=temp.l=0;
	return temp;
}
range same(range a,range b)//求并集 
{
	range temp;
	temp.l=(a.l>b.l)?a.l:b.l;
	temp.r=(a.r<b.r)?a.r:b.r;
	if(temp.l>temp.r)temp.l=temp.r=0;
	return temp;
}
int main()
{
	int i,j,k,h,m;
	double a1,a2,a3,b1,b2,b3,sum;
	range temp[3][2],aa;
	while(scanf("%lf",&d)&&d!=-1)
	{
		sum=0;
		for(h=0;h<12;h++)
		for(m=0;m<60;m++)
		{
			b1=6.0*m;                a1=-5.9;
            b2=30*h+0.5*m;           a2=1.0/120-6.0;
            b3=30*h+(0.5-6)*m;       a3=(1.0/120)-0.1;
            temp[0][0]=work(a1,b1);temp[0][1]=work(-a1,-b1);
            temp[1][0]=work(a2,b2);temp[1][1]=work(-a2,-b2);
            temp[2][0]=work(a3,b3);temp[2][1]=work(-a3,-b3);
            for(i=0;i<2;i++)
            for(j=0;j<2;j++)
            for(k=0;k<2;k++)
            {
            	aa=same(same(temp[0][i],temp[1][j]),temp[2][k]);
            	sum+=aa.r-aa.l;
            }
		}
		sum=sum*100.0/(3600*12);
		printf("%.3lf\n",sum);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值