2 Trains and Fly Problem. Find the number of trips made by the fly back and forth. Question: A Train A is approaching at a speed of 10m/sec, another Train B moving in the opposite direction at a speed of 20m/sec. A fly whose absolute speed is 50m/sec goes repeatedly from A to B and back, without loosing any time at any of the trains. The repeated moving back and forth stops when the 2 trains crash into each other. 
The initial distance between the 2 trains is 300m.

1>Find the distance traveled by the fly 

2>Find the number of trips made by the fly back and forth

My Question: I get that the answer to the first question is 500m, since it takes 10 seconds for the 2 trains to crash, so in 10 seconds at a speed of 50m/sec the fly covers 50m/sec*10sec = 500m.

But how do I find the number of trips(back and forth) the fly makes until the trains crash?
But an engineering solution might be to say that the fly stops going back and forth when the distance between the trains is equal to the fly's length, say $1$ cm. After all the work he's done, the poor guy starts getting smashed after this time. The distance between the trains could be expressed as, $D(t)=300-30t$, where $D$ and $t$ are in units of meters and seconds, respectively. To avoid the infinite result, we can calculate the trips the fly makes up until he starts getting smashed, $T_{smash}=\frac{300-\frac{1}{100}}{30}=9.999667$ seconds. Seems like the number of round trips the fly makes ($N$) can be approximated as:

$$ N=\frac{1}{2}\int_{0}^{T_{smash}} \frac{dt}{\frac{D(t)}{v}} $$ where $v=50$ m/s is the fly's speed and the $1/2$ multiplier is to make $N$ equate to 'round trips'. This computes to $$N\dot = 8.59.$$ 

Cheers,

Paul Safier
The problem can be solved much more simpler by using graphs. A plot of d(t) vs t for the trains A and B will be two straight line who intersect at the time and position where the two trains crash. Furthermore, plotting the d(t) of the bird on the same plane will show clearly where the fly keeps going to and fro between the two train plots….The graphical solution is simple and easy to understand