#P13858. [SWERC 2020] Rule 110
[SWERC 2020] Rule 110
题目描述
:::align{center}
:::
Ann is decorating her office with the coolest arrangement of lights ever. She is using very long LED strips, where each individual cell is switched on or off every second, according to the following simple and pretty algorithm. At each step, the status of each cell (0 for off and 1 for on) is determined from the status of its two neighbor cells on the strip (left and right) and its own status, according to the following table:
$$\begin{array}{l|c|c|c|c|c|c|c|c} \textbf{Current pattern} & 111 & 110 & 101 & 100 & 011 & 010 & 001 & 000 \\ \hline \textbf{New state for center cell} & 0 & 1 & 1 & 0 & 1 & 1 & 1 & 0 \\ \end{array} $$Ann is choosing an initial configuration for the cells and she marvels at the resulting animation, which happens to be highly similar to Conway's Game of Life, with interesting behavior on the boundary between stability and chaos.
输入格式
The input is composed of two lines.
- The first line contains the initial configuration, as a string of 16 characters and . All the cells to the left and to the right of this string are considered to be 0.
- The second line contains the number of steps to perform.
Limits
- The LED strip is considered to be large enough to ensure that no 1-cells will ever reach the ends of the strip.
输出格式
The output should contain a single line with a single integer that is the total number of 1-cells in the final configuration.
0001001101111100
5
11
提示
Sample Explanation
the output is since we have the following five steps:
$$\begin{aligned} \texttt{...0000000010011011111000...}\\ \texttt{...0000000110111110001000...}\\ \texttt{...0000001111100010011000...}\\ \texttt{...0000011000100110111000...}\\ \texttt{...0000111001101111101000...}\\ \texttt{...0001101011111000111000...}\\ \end{aligned} $$where everything not displayed contains only 0-cells.