hdu-Tick and Tick

本文针对HDU在线评测平台上的TickandTick问题,详细解析了如何通过计算时钟三针之间的角度来确定“快乐”状态的时间百分比。文章提供了具体的数学模型和C语言实现代码。

hdu-Tick and Tick解题报告

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
 

题目大意

输入一个非负整数D,当时针、分针、秒针,之中任意两者之间的夹角大于D,则会happy。现在要求总的happy的时间占的百分比(基于12个小时),保留三位小数。



解题思路

1、每秒钟的移动速度(多少度),(s:秒针,m:分针,h:时针):   s=6 /s           m=(1/10) /s           h=(1/120) /s

2、三种针之间相对速度 :      s_m=(59/10) /s           s_h=(719/120) /s            m_h=(11/120) /s

3、移动一度所需要的时间:   s_m=(10/59) s            s_h=(120/719) s             m_h=(120/11) s

4、周期:       ts_m=(3600/59) s                 ts_h=(43200/719) s                tm_h=(43200/11) s

所以,假设输入的D=n;则有:

                                                n*s_m + k1*ts_m < T < ts_m - n*s_m + k1*ts_m

                                                n *s_h + k2*ts_h < T < ts_h - n*s_h + k2*ts_h

                                                n* m_h + k3*tm_h <T < tm_h - n*m_h +k3*tm_h

当T同时满足这三个式子时,便是happy的时间;


#include<stdio.h>
#include<math.h>
int main()
{
    int t;
    double n,sm,sh,mh,tsm,tsh,tmh,fsm,fsh,fmh,esm,esh,emh,b1,e1,b2,e2,b3,e3,min,max,sum;
    sm=10.0/59.0;
    sh=120.0/719.0;
    mh=120.0/11.0;
    tsm=3600.0/59.0;
    tsh=43200.0/719.0;
    tmh=43200.0/11.0;
    while(~scanf("%lf",&n))
    {
        if(n<0)break;
        sum=0;
        fsm=n*sm;esm=tsm-fsm;
        fsh=n*sh;esh=tsh-fsh;
        fmh=n*mh;emh=tmh-fmh;
        for(b3=fmh,e3=emh;e3<=43200;b3+=tmh,e3+=tmh)//找出满足三个式子的T,并且求和得到sum
        {
            for(b2=fsh,e2=esh;e2<=43200;b2+=tsh,e2+=tsh)
            {
                if(e2<b3)
                    continue;
                if(b2>e3)
                    break;
                for(t=0,b1=fsm,e1=esm;e1<=43200;t=t+1,b1=fsm+t*tsm,e1=esm+t*tsm)
                {
                    if(e1<b2||e1<b3)
                        continue;
                    if(b1>e2||b1>e3)
                        break;
                    max=b1>b2?b1:b2;
                    max=max>b3?max:b3;
                    min=e1<e2?e1:e2;
                    min=min<e3?min:e3;
                    sum+=min-max;
                }
            }
        }
        printf("%.3lf\n",sum/432.0);//因为要求百分比,所以sum应该除以12个小时即43200秒,再乘以100
    }
    return 0;
}

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值