Polar Bear
Time limit5sMemory limit128 MB
Simulate Conway's Game of Life on concentric rings with special opposite-cell neighbors, then report the live count and lexicographic first and last live cells after g steps.
- Level
Medium6 of 10
- Topics
- Simulation, Array, Implementation
- Solved
- No attempts yet
Problem
This is Conway's Game of Life played on polar-coordinate graph paper instead of a rectangular grid. The board has concentric rings and radial lines. The rings are numbered from the outside inward, for the outermost ring up to for the innermost ring. Because each ring is divided by the radial lines, it contains exactly cells. A cell is identified by a pair : its ring () and its position (), counted clockwise from a fixed radius. The number of radial lines is always even.
At every tick all cells update simultaneously under the usual Game of Life rules: a dead cell with exactly three live neighbors becomes live in the next generation; a live cell with fewer than two or more than three live neighbors becomes dead; every other cell keeps its state.
Every cell has exactly eight neighbors, defined as follows (all position indices are taken modulo ):
- An interior cell with has the eight neighbors , , , , , , and .
- A cell on the outer ring has the five ordinary neighbors , , , , together with the diametrically opposite cell on the same ring and that cell's two ring neighbors and .
- A cell on the inner ring has the five ordinary neighbors , , , , together with the diametrically opposite cell and its two ring neighbors and .
Input
The input contains several test cases. Each test case begins with two positive integers and (, , with even), the number of rings and the number of radial lines. Next comes a positive integer followed by distinct pairs of integers (which may span several lines); each pair gives the ring and position of one initially live cell. After the pairs comes a single nonnegative integer (), the number of generations to simulate. The last test case is followed by a line containing two zeros, which is not processed.
Output
For each test case, print Case X: (where X is the test case number, starting from ) followed by five integers: the number of live cells after generations, then , the position of the lexicographically first live cell, and , the position of the lexicographically last live cell. Cells are ordered lexicographically by ring number and then by position. If no cells are alive, print 0 -1 -1 -1 -1 for those five integers.