← 返回 openai 的题目列表Cell Simulation / Conway's Game of Life
类型:online_judge
Problem: Cell Simulation
You are given an R x C 2D grid. Each cell is either:
1: alive
0: dead
Simulate the grid for T steps and output the final state.
For each cell, count the number of live cells among its 8 neighboring positions. Positions outside the grid are considered dead.
Rules:
If the current cell is alive:
It dies if it has fewer than 2 live neighbors.
It survives if it has 2 or 3 live neighbors.
It dies if it has more than 3 live neighbors.
If the current cell is dead:
It becomes alive if it has exactly 3 live neighbors.
Otherwise, it remains dead.
Input Format
The first line contains three integers:
R C T
The next R lines each contain a binary string of length C, representing the initial grid.
Output Format
Print R lines, each of length C, representing the grid after T simulation steps.
Constraints
1 <= R, C <= 200
0 <= T <= 100
Example
Input:
3 3 1
000
111
000
Output:
010
010
010
Example
Input
3 3 1
000
111
000
Output
010
010
010