#C14893. SIR Model Grid Simulation
SIR Model Grid Simulation
SIR Model Grid Simulation
This problem simulates the spread of an infection in a grid-like city using a modified SIR model. The city is represented as an n × n grid. Initially, exactly one cell is infected, and the remaining cells are susceptible. At each simulation step, every infected cell may recover with probability \(q\) or infect its adjacent (up, down, left, right) susceptible neighbors with probability \(p\) if it does not recover. The simulation runs for \(t\) time steps. Note: To ensure that submissions in all languages lead to identical outputs, you must use the deterministic linear congruential generator (LCG) defined in the problem (see below) for all randomness rather than built-in random functions.
The LCG is defined by:
[ \text{state} = (\text{state} \times 1103515245 + 12345) \mod 2^{31} ]
and the random number \(r\) in the range [0, 1) is given by:
[ r = \frac{\text{state}}{2^{31}}. ]
</p>For every simulation step, after processing all cells, output one line containing three integers separated by a space: the number of susceptible cells, the number of infected cells, and the number of recovered cells at that time step.
Example: For a 3×3 grid with parameters \(p=1,\; q=0,\; t=2\) and using the deterministic LCG (with an initial seed of 1), the simulation might proceed as follows (note that the initial infected cell is determined by the LCG):
- Step 1: After infection spreads deterministically, the output line is:
5 4 0
. - Step 2: Infection further spreads; the output line is:
2 7 0
.
Your task is to implement the simulation according to these rules. Use the LCG (with an initial seed of 1) for all randomness to obtain deterministic behavior.
inputFormat
The input is read from standard input and consists of a single line containing four values separated by spaces:
n
: an integer representing the size of the grid (the grid is n x n).p
: a float representing the infection probability.q
: a float representing the recovery probability.t
: an integer representing the number of simulation steps.
For example:
3 1 0 2
outputFormat
For each simulation step, print a line with three space‐separated integers: the number of susceptible cells, the number of infected cells, and the number of recovered cells after that step.
For example, the output for the sample input above might be:
5 4 0 2 7 0## sample
3 1 0 2
5 4 0
2 7 0
</p>