Based on the ray tracing theory, the authors put forward an improved trial firing path tracing algorithm, which can simulate the propagation of rays in layered media quite accurately. This algorithm can not only figure out the journey time and the ray paths of all reflection waves received by any detection point but also has the merits of rapidness, accuracy and adaptability to complex structural models. With the conjugate gradient method and through altered iteration of the forward model, the authors studied the inverse algorithm of the microearthquate layered model. Finally, inversion of practical test data was performed, and the result is basically consistent with the real data.