#K68057. Bacterial Colony Growth Simulation
Bacterial Colony Growth Simulation
Bacterial Colony Growth Simulation
This problem involves simulating the growth of a bacterial colony in a petri dish following rules similar to Conway's Game of Life. The petri dish is represented as a grid of n rows and m columns. Each cell in the grid can either be alive (represented by 1) or dead (represented by 0).
The simulation is performed for k generations. In each generation, the next state of the grid is computed according to the following rules:
- If a cell is alive and it has $N$ live neighbors, then it survives if and only if $N = 2$ or $N = 3$. Otherwise, it dies.
- If a cell is dead and it has exactly 3 live neighbors (i.e. $N = 3$), then it becomes alive.
Note that a neighbor is any cell adjacent in one of the 8 directions (horizontal, vertical, and diagonal).
Your task is to simulate this process, taking the initial state of the grid as input, and output the state of the grid after k generations.
inputFormat
The input is read from standard input and has the following format:
n m k row1 row2 ... rown
Here:
n
is the number of rows in the grid.m
is the number of columns in the grid.k
is the number of generations to simulate.- Each of the next
n
lines containsm
integers (each either 0 or 1) separated by spaces representing the initial state of the grid.
outputFormat
Output to standard output the final state of the grid after k generations. The output should have n
lines, each containing m
integers separated by spaces.
3 3 1
0 1 0
0 1 0
0 1 0
0 0 0
1 1 1
0 0 0
</p>