G - Nana in Wonderland Series--Dream Awake Time Limit: 2000/1000ms (java/others) Memory Limit: 128000/64000kb (java/others) special Judge Problem Description
Nana left the kingdom, to the distance, in the wilderness, Nana saw a big clock, the hour and minute hand on the hands are slowly turning, the wings of the Angel and then appeared, the Angel said: "Outside the sky is already light, nana you do not oversleep yo ~", Nana asked: "How can I wake up?" The angel said, "As long as this clock coincides with the hour hand and the minute hand, you can enter the time tunnel and leave this place." ”
Can you tell Nana how long the hour and minute hand will coincide?
Input
Multiple sets of data, the first line is a positive integer t (t<=100,000), which represents the number of groups of data
For each set of data, for a moment, the format is HH:MM:SS, respectively, the time, minute, and second (using the 24-hour timekeeping method, ranging from 00:00:00~23:59:59)
Output for each set of data, outputs a floating-point number that represents the seconds between the next hour and minute hand, and the error is considered correct within 1e-4. Sample Input
223:59:5900:00:00
Sample Output
1.0000003927.272727
Hint Use special judge
Test instructions: For a moment, ask how many seconds it takes to coincide with the next hour and minute hand.
Solution: A day, the hour and minute hand total coincident 24 times, you can calculate these 24 times, in fact, is 12/11 of the integer times the hour, converted into seconds is 12*3600/11*k seconds (k=1,2,..., 24), and then for every moment, Enumeration search the next coincident moment is which, subtract. How did this come to be calculated? We can certainly be sure that 00:00:00, the hour and minute hand will coincide, so when is the next coincidence? The hour hand turns round is 12 hours, in this 12 hours, the hour hand and the minute hand coincide 11 times, therefore the adjacent two times coincident interval is 12/11 hours.
Note: I am pushing the formula out and counting the number of seconds to be coincident per hour after saving. {(s/3600+h) *30=s/3600*360-s=3600/11*h}
1#include <stdio.h>2#include <string.h>3 4 intMain ()5 {6 intt,i,j,k,h,m,s;7 Doublesec[ -],n;8 Chartime[Ten];9 for(i=0;i< A; i++)//Save 12 hours of coincident secondsTen { Onesec[i]=i*3600*1.0/ One; A } - while(SCANF ("%d", &t)! =EOF) - { the while(t--) - { -scanf"%s", time); -H=Ten* (time[0]-'0') + (time[1]-'0'); +m=Ten* (time[3]-'0') + (time[4]-'0'); -s=Ten* (time[6]-'0') + (time[7]-'0'); +s=m* -+s; A if(h>= A) ath-= A; - if(s>=sec[h])//The current second is greater than the coincident seconds value, the next coincident second equals the number of seconds of the current time distance of the next hour + the number of seconds coincident in the next hour - { -n=3600-s; - if(h== One) -H=0; in Else -h++; ton+=Sec[h]; + } - Else the { *n=sec[h]-s; $ }Panax Notoginsengprintf"%.6lf\n", n); - } the + } A return 0; the}
G-Nana in Wonderland Series--Dream Awake