HDOJ1006(滴答滴)

本文探讨了时钟上的三根指针(时针、分针、秒针)如何通过保持一定角度距离来达到“幸福”状态的问题,并提供了一段C++代码用于计算一天内这些指针处于幸福状态的百分比。

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

Tick and Tick

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


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(范围是0~120),输入以输入D为-1的时候结束。

输出:

对每个输入的D,打印出指针嗨皮的时间占一天总时间的比例,结果精度三位数


分析:


代码


#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
double vsm=59.0/10,vsh=719.0/120,vmh=11.0/120;//速度差值 度/秒
double tsm=360.0/vsm,tsh=360.0/vsh,tmh=360.0/vmh;//360度为一个周期 一个周期的时间是多少 Q1:何时重合 相差360度时候
double b1,b2,b3;//开始时间
double e1,e2,e3;//结束时间
int k1,k2,k3;
double total,angle,start,ended;
int main(){
    while (cin>>angle,angle != -1){
            total=0;
            b3=angle / vmh;//相差角度是angle的时候经过的时间
            e3=(360-angle)/vmh;
            b1=angle/vsm;
            e1=(360-angle)/vsm;
            b2=angle/vsh;
            e2=(360-angle)/vsh;
            while(b3<43200){//12h*60min*60s
                while(b1<e3){
                    while(b2<e3&&b2<e1)
                    {
                      start=max(max(b1,b2),b3);
                      ended=min(min(e1,e2),e3);
                      total+=(ended-start>0)?ended-start:0;
                      b2=b2+tsh; e2=e2+tsh;//控制跳出已经完成一个周期
                    }
                    b2=b2-tsh;e2=e2-tsh;
                    b1=b1+tsm;e1=e1+tsm;
                }
                b1=b1-tsm;e1=e1-tsm;
               b3=b3+tmh; e3=e3+tmh;
            }
            cout<<fixed<<setprecision(3)<<total/432<<endl;//fixed是以固定点方式显示,小数点后几位,除非cout.unsetf( iOS::fixed );否则一直在
    }
    return 0;
}


结果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值