#P3945. N-Body Gravitational Simulation

    ID: 17193 Type: Default 1000ms 256MiB

N-Body Gravitational Simulation

N-Body Gravitational Simulation

In this problem, you are given N celestial bodies. Each body is specified by its initial spatial coordinates \( (x_i, y_i, z_i) \), its initial velocity \( (v_{x_i}, v_{y_i}, v_{z_i}) \) and its mass \( M_i \). Under the influence of gravitational force, the time evolution is not continuous but is updated every \(0.01\) seconds (i.e. the simulation time step is \(\Delta t=0.01\) seconds). All bodies are considered as point masses.

You are also given a time \( t \). Your task is to compute and output the coordinates of all the bodies at time \( t \). Use the universal gravitational constant \( G \) given by:

[ G = 6.67408 \times 10^{-11} ]

You may define it in your code as:

#define G 6.67408e-11

An answer is considered correct on a test case if the relative error compared to the standard answer (which prints 12 digits after the decimal point) does not exceed \(0.5\%\). Special Judge (SPJ) is enabled.

inputFormat

The input begins with a line containing two values: an integer \( N \) (the number of bodies) and a floating-point number \( t \) (the simulation time in seconds).

Then follow \( N \) lines, each containing 7 numbers:

\( x_i \) \( y_i \) \( z_i \) \( v_{x_i} \) \( v_{y_i} \) \( v_{z_i} \) \( M_i \)

All values are space‐separated. It is guaranteed that \( t \) is at least \( 0 \) and that the simulation time \( t \) can be covered by a whole number of \(0.01\) second steps or with one additional partial step.

outputFormat

Output \( N \) lines. The \( i \)-th line should contain three floating-point numbers representing the coordinates of the \( i \)-th body at time \( t \): the \( x \), \( y \) and \( z \) coordinates. Each number must be printed with 12 digits after the decimal point, and the relative error of each coordinate must be within \(0.5\%\).

sample

2 0.01
0 0 0 1 0 0 100000
1 0 0 -1 0 0 100000
0.010000000000 0.000000000000 0.000000000000

0.990000000000 0.000000000000 0.000000000000

</p>