#P17218. [ICPC 2017 Nanning R] The Game of Life

[ICPC 2017 Nanning R] The Game of Life

题目描述

:::align{center} :::

From an evolutionary gene’s-eye perspective, the genes are immortal, and our role, the meaning of life, is to perpetuate the genes. In a few centuries, all traces of our existence as human individuals, memories of us, all our accomplishments, will likely be gone and forgotten, except for genes that survive from those of us who successfully reproduced through the generations.

Of course, we do not experience the world from a gene’s eye evolutionary perspective, but the Game of Life does. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells. Each cell is in one of two possible states, alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically or diagonally adjacent. At each step in time, the following transitions occur.

Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.

Any live cell with two or three live neighbours lives on to the next generation.

Any live cell with more than three live neighbours dies, as if by overpopulation.

Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern, the 00-th generation, is given by a finite N×MN \times M grid where N≤3N \le 3 and M≤5M \le 5 as a part of the infinite grid. That implies that the state of any other grid is dead.

Genetic evolution is the meaning of biologic life, in that it is the why and how of it, as well as the stock of future biological existence. The trinity life in the game requests you to find answers of three problems.

At what point in the first 321321 generations, including the 00-th generation, will the population be at its maximum?

And what is that maximum?

What will the population be at the 321321-th generation?

输入格式

The first line of the input contains an integer t(1≤t≤300)t (1 \le t \le 300) specifying the number of test cases.

Each case consists of several lines. The first line contains two positive integers NN and MM. Each of the next NN lines contains a string of length MM, corresponding the initial pattern. We use “#” to describe a cell which is alive, and use “.” to describe a cell which is dead.

输出格式

For each test case, output three integers aa, bb and cc in a line, where aa means the aa-th generation, bb is the population at that generation, and cc is the population at the 321321-th generation. If there are several generations whose population meets the maximum, choose the smallest aa for the output.

3
3 3
...
##.
.#.
3 3
.#.
...
###
3 3
...
###
...
1 4 4
10 20 12
0 3 3