The second question of Java Group B of the 8th Blue Bridge Cup National Championship


Title: Game of Life


Conway's Game of Life is a cellular automaton invented by British mathematician John Horton Conway in 1970.  
The game is played on an infinite 2D grid.


Initially, each small square is populated by a living or dead cell.
The state of each cell at the next moment is determined by the state of the cells in the eight grids around it.


Specifically:


1. When the current cell is in a viable state, when there are less than 2 (excluding 2) viable cells around, the cell becomes a dead state. (The number of simulated life is scarce)
2. When the current cell is alive, when there are 2 or 3 living cells around, the cell remains the same.
3. When the current cell is in a viable state, when there are more than 3 viable cells around, the cell becomes a dead state. (The number of simulated lives is too much)
4. When the current cell is in a dead state, when there are 3 surviving cells around, the cell becomes a living state. (Simulated reproduction)


After all cells of the current generation are processed by the above rules at the same time, the next generation cell map can be obtained. Continue to process the cell map of this generation according to the rules, and you can obtain the cell map of the next generation, and repeat.


For example, suppose the initial is: (X stands for live cells, . for dead cells)
.....
.....
.XXX.
.....


The next generation will become:
.....
..X..
..X..
..X..
 …


Conway's Game of Life will have some interesting modes. For example a stable pattern:


....
.XX.
.XX.
....


and looping patterns:


...... ......
.XX... .XX... .XX...
.XX... . X.... .XX...
...XX. -> ....X. -> ...XX.
...XX. ...XX. ...XX.
..... . . . .




We're going to discuss a very special mode in this question, called the "Gosper glider gun"


: ......................................................
X. ..........................................................
XX
.................................... .........XX...XX............XX.
............X...X.. ..XX............XX.
.XX........X.....X...XX............ ....
XX........X...X.XX....XX
..........................................X.. ...X.......X..............................
X...X......... ............
.............XX
...................................................................... .................................


Assuming the above initial state is the 0th generation, how many living cells are there in the 1000000000th (billion) generation?


Note: We assume that the cellular machine operates on an infinite 2D grid, not just the space drawn in the title.
Of course, for distant locations, the initial state is always dead cells.


Note: What needs to be submitted is an integer, do not fill in redundant content.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326929836&siteId=291194637