hdu.Tick and Tick

本文介绍了一种算法,用于计算一天中秒针、分针和时针三者之间的角度大于给定阈值的时间比例。通过精确计算不同指针间的相对速度及它们形成特定角度的时间段,最终得出所有指针都满足条件的总时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Problem Description

The three hands of the clock arerotating every second and meeting each other many times everyday. Finally, theyget 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 tocalculate 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 thepercentage of time in a day that all of the hands are happy, accurate up to 3decimal places.

本题将三个指针的角度均小于D的时间累加起来即可;

SH,SM, MH来表示秒针时针,秒针分针,分针时针的相对速度;

将秒针时针,秒针分针,分针时针相差度数小于D的时间用

b1,e1; b2, e2; b3, e2表示取交集并累加

以下代码:

#include<iostream>

#include<algorithm>

#include<stdio.h>

usingnamespace std;

constdouble SH = 719.0/120, SM = 59.0/10, MH = 11.0/120;

constdouble tSH = 43200.0/719, tSM = 3600.0/59, tMH = 43200.0/11;

doubleMin(double a,double b,double c) 

    return min(a, min(b, c)); 


doubleMax(double a,double b,double c) 

    return max(a, max(b, c)); 

 

intmain()

{

       double D;

       while(scanf("%lf", &D)&& D != -1){

              double sumtime = 0, begin, end;

              double bSM, bSH, bMH, eSM, eSH,eMH;

              bSH = D / SH;

              bSM = D / SM;

              bMH = D / MH;    // 第一次的开始时间

              eSH = (360 - D) / SH;

              eSM = (360 - D) / SM;

              eMH = (360 - D) / MH;  // 第一次的结束时间

              //   需满足条件

              for (double b1 = bMH, e1 = eMH; e1<= 43200.000001; b1 += tMH, e1 += tMH)

              {

                     for (double b2 = bSM, e2 =eSM; e2 <= 43200.000001; b2 += tSM, e2 += tSM)

                     {

                            if (b1 > e2)

                                   continue;

                            if (b2 > e1)

                                   break;

                            for (double b3 =bSH, e3 = eSH; e3 <= 432000.000001; b3 += tSH, e3 += tSH)

                            {

                                   if (b2 >e3 || b1 > e3)

                                          continue;

                                   if (b3 >e2 || b3 > e1)

                                          break;

                                   begin =Max(b1, b2, b3);

                                   end = Min(e1,e2, e3);

                                   sumtime +=end - begin;

                            }

                     }

              }                 //将交集的时间累加;

              printf("%.3lf\n",sumtime / 432);

       }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值