Test instructions is given a current time and angle A, asking how much time to form angle A from the next hour and minute hand starting now, and the time to take the whole down.
Analysis: Clockwise 3600s walk 30°, so 120s go 1°, the minute 3600s walk 360°, so 10s go to 1°, then each 120s they will be 11 °, that is, each over 120/11s difference 1 °, so set tar is from 0:0 0:00 the number of seconds elapsed from the current time, CNT is the same, but the initial value of CNT is a° multiplied by 120/11s, that is, it is the first time from 0:00:00 to form the angle A, And then constantly change to the next angle of a time can (all the time first in seconds to represent, and finally converted to time), until the tar, then it is the first over the current time and formed an angle a time. One problem to note, however, is that the accuracy problem can occur when multiplied by a fraction (in fact it does appear in this question), so it can be removed from 1 seconds to 11 smaller units, which means that all the time is converted into smaller units (that is, multiplied by 11), which avoids the problem of precision.
See the code for details:
1#include <stdio.h>2 intMain ()3 {4 inth,m,s,a,da,tots= A*3600* One, kase=1;5 while(SCANF ("%d:%d:%d", &h,&m,&s) = =3)6 {7 intTar = One* (h*3600+m* -+s);8scanf"%d",&a);9Da = the-2*A;Ten intCNT = A * -, F =1; One //The position at the beginning is a° (obviously the first minute is the second hand in front) . A while(cnt<=tar) - { - if(f) the { -f=0; -cnt+=da* -;//The first Chase is the angle of the minute hand Chase (360-2*a), in order to form the difference a° again. - //this time the minute hand is in front of the hour a° + } - Else + { Af=1; atcnt+=2*a* -;//Chase 2*a° Again, the minute hand a° in front of the hour hand - //After that, it repeats until the current time is exceeded . - } - } - if(cnt>=tots) cnt-=Tots; - intAnsh,ansm,anss; inAnsh = cnt/(3600* One); -cnt%=3600* One; toansm=cnt/( -* One); +cnt%= -* One; -anss=cnt/ One; theprintf"Case #%d:%02d:%02d:%02d\n", kase++, ANSH,ANSM,ANSS); * } $ return 0;Panax Notoginseng}
HDU 5705 Clock (2016 Hangzhou Electric Girls Session 1004)--angle chase and problem