HDOJ1006(滴答滴)

xiaoxiao2021-02-27  145

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; }

结果:

转载请注明原文地址: https://www.6miu.com/read-14051.html

最新回复(0)