It is known that there are two buses at the bus station at the door of my house.
One of them passes through my house every m minutes.
Another car goes through my house every n minutes.
I can wait for a car to take a bus to work ....
SoAverageHow long can I wait for a car ??
The application scenario is for map pathfinding.Algorithm... Calculate the waiting time (used to estimate how long it will take you to reach your destination ).
A very simple tip: if there is only one car m, the average time is m/2. If there is one more car n... the time used must be less than M/2.
PS: There are many friends who will think the answer is (m + n)/2, which is obviously incorrect, because I just need to wait for a car to go to work.
PS: M * n/(m + n) is also incorrect.
PS: I don't know when to get out and wait for the bus, and I don't know when M and N start. It's random.
Some simple verification logic is attached for checking:
Assume that the result is S.
So there must be
S <n/2
S <m/2
Suppose M is very large, so s must be approximately equal to n/2.
PS: so far, the fastest friend has spent 40 minutes to figure out...---# amount... in fact, this question is very simple.
PS: DoProgramI 've been doing this for too long. Don't get stuck.... try to figure it out and see if my mind can be turned over.
PS:... release some answers first
1. When M = N, the interval between the two vehicles is equal, so the interval between the two buses is very important.
Assuming that the time interval is K, the average time is from 0 to N (2 k * k + N * n-2kn) DK/2n * n
The average waiting time is N/3.
The credit picture cannot be obtained.
2. When 2n> m> N
Assuming that the time interval is K, the average time is from 0 to m for K credits.
(2 k * k + 2n * n + M * m-2mk-2mn-2nk) DK/2 M * m
Result: (3N * m * m-9m * n + 11N * n * N)/18 m * m
If this is an error, please correct it.