Tick and tick
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)Total Submission (s): 10770 Accepted Submission (s): 3008
problem Description
The three hands of the clock is Rotating every second and meeting all other many times everyday. Finally, they get bored of this and all of the them would like to stay away from the other. A Hand is happy if it's at least D degrees from any of the rest. You is to calculate what much time in a day and all the hands is happy.
Input
The input contains many test cases. Each of them have a single line with a real number D between 0 and inclusively. The input is terminated with a D of-1.
Output
for each D, print in a, the percentage of time in a, and all of the hands is happy , accurate up to 3 decimal places.
Sample Input
0
+
1
-
Sample Output
100.000
0.000
6.251
Author
PAN, Minghao
Source
ZJCPC2004
now there is a normal clock, sometimes needles, minutes, seconds, seconds, second hand is not a second a second interrupted, but even
continued to go. Give you a degree d (less than or equal to 120°). 24 hours, three pointers over this degree of time
What percentage of time is there?
thought: Before the thought of the simulation of a second time can be. Did not expect the time is continuous, but not the interval, referring to the comments
Area to know how to do it. By the way, worship the great God ...
Angular speed of the three-pointer walk:
Second hand speed s = 6°/s, minute speed m = (1/10) °/s, hour speed h = (1/120) °/s
The relative velocity difference between the three pointer 22 is:
Seconds difference S_h = (719/120) °/s, seconds difference s_m = (59/10) °/s, time difference m_h = (120/11) °/s
The time difference was once needed
Second time difference sh = (120/719) s/degrees, seconds difference sm = (10/59) s/degrees, time difference MH = (120/11) s/degree
The difference of 360 ° required time is
Seconds of phase difference tsh = 43200.0/719, seconds difference tsm = 3600.0/59, time difference tmh = 43200.0/11
All three need a minimum difference between d° to meet the conditions, set T to three pointers meet the total time of the condition, then T satisfies the following
Conditions:
N*sh + K1*tsh < T < Tsh-n*sh +k1*tsh
N*SM + K2*TSM < T < TSM-N*SM + K2*TSM
N*MH + K3*TMH < T < TMH-N*MH + K3*TMH
First find out the first time between three pointers 22 satisfies the condition and the first time the condition is not satisfied.
The start and end times that meet the criteria between the 22 pointers are traversed (triple loop), when all conditions are met
Sum up is the total time to satisfy the conditions. The final result is: The total time of satisfying the/43200*100.
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;//seconds Speed s = 6°/s minute speed m = 1/10°/s hour h = 1/120°/sconst double SH = 719.0/120, SM = 59.0/10, MH = 11.0/120;const do Uble TSH = 43200.0/719, TSM = 3600.0/59, TMH = 43200.0/11;double min (double a,double b,double c) {return Min (A,min (B,C) );} Double Max (double a,double b,double c) {return Max (A,max (B,c));} int main () {double D; while (Cin >> D && d!=-1) {double bsh,bsm,bmh,esh,esm,emh,begin,end,sum = 0; BSH = d/sh; BSM = D/SM; BMH = D/MH; Calculates the time at which the condition was first met (start time) ESH = (360-d)/sh; ESM = (360-d)/sm; EMH = (360-d)/mh; Calculates the first time that the condition is not met (end time) for (double B3 = Bsh,e3 = ESH; E3 <= 43200.000001; b3+=tsh,e3+=tsh) {for (Double b2 = Bmh,e2 = EMH; E2 <= 43200.000001; b2+=tmh,e2+=tmh) {if (E2 < B3)//Determine if there is an intersection continue; if (B2 > E3) break; for (double B1 = bsm,e1 = ESM; E1 <= 43200.000001; b1+=tsm,e1+=tsm) {if (E1 < B2 | | E1 < B3) continue; if (B1 > E2 | | b1 > E3) break; Begin = Max (B1,B2,B3); The start time takes maximum to meet all requirements End = Min (E1,E2,E3); The end time is minimized to meet all requirements Sum + = (end-begin); }}} printf ("%.3lf\n", sum/432); } return 0;}
HDU1006 Tick and tick "calculate geometry"