Problem No. 1 —Anthrax Lab Studies

Executable Program : PROG1.EXE, PROG1.CLASS

Source Program: PROG1.CPP, PROG1.JAVA, PROG1.C, PROG1.PAS

Input file: PROG1.IN Output file: PROG1.OUT

 

Anthrax, also called Splenic Fever, Malignant Pustule, or Woolsorters' Disease, is caused by Bacillus anthracis, an organism that under certain conditions forms highly resistant spores capable of maintaining its virulent effect for many years in contaminated soil and other materials.

Anthrax was the first human disease that was demonstrated to be caused by a specific microrganism. It was also the first infectious disease against which a bacterial vaccine was found to be effective (Louis Pasteur in 1881). These discoveries led to the origin and development of bacteriology and immunology.

Interest has reborn around the study of how infected cells reproduce and die. A hypothesis states that cell reproduction can be modelled as a two-dimensional infinite grid of square cells like chessboard cells but in Practical lab studies its defined as finite grid. In this grid, each cell is considered to be alive or dead. A living cell is represented as a mark on its position in the grid. Each cell has up to 8 neighbouring cells (up, down, left, right, upper-right, upper-left, lower-right and lower-left). Cells located in the border of the grid have smaller number of neighbours.

The model starts with an Initial Generation (G0) consisting of some living and death cells in the Grid. After reproduction rules are applied to every Cell, a new Generation G1 is obtained. New generations are always created using the information of the previous generation. That is Generation Gi is created based on information of Generation Gi-1

The reproduction rules that are used in the model are:

    1. A dead cell with exactly three living neighbours becomes a living cell (birth).
    2. A living cell with cero or one living neighbours dies (loneliness).
    3. A living cell with two or three living neighbours stays alive (survival).
    4. A living cell with four or more living neighbours dies (overcrowding).

In all other cases, a cell dies. Existing death cells remain death (overcrowding or loneliness).

 

EXAMPLES.

This initial generation will evolve in a generation where all cells die.

This initial generation yields generations that will always be the same as the initial.

 

If the initial generation is the next generation will be the following generations will be alternating between these two generations.

In more complex cases, it is impossible to look at a starting position (or pattern) and see what will happen in the future. The only way to find out is to follow the rules

INPUT

The input of the program will be a text file, (located in the same path as the executable). The input will contain data for several runs, each run will have the following information:

The first line has two numbers indicating the X and Y dimensions of the grid. (X number of columns, Y number of rows). A 0 in this first line indicates end of run.

The second line is one number representing the number of generations that must be obtained.

The third line is a number, that specifies the number of cells that have a microrganism.

Starting in the forth line, there will be the coordinates of each microrganism, one per line with format x, y (x is column number and y is row number). The row and column numbers start at 1.

OUTPUT

The output is a text file (located in the same path that the program). In this file you have to show the different generations starting with the Initial Generation. A Generation is represented as a matrix showing Living microrganisms as an "*" (asterisk) and death cells as a "0" (cero).

Before printing the Initial Generation you should output the study number. Before the Initial Generation write the string "Initial Generation". Before each new generation write "Generation x", where "x" is the generation number.

SAMPLE INPUT FILE

15 10

5

3

5 5

5 6

5 7

0

SAMPLE OUTPUT FILE

Study 1

Initial Generation

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 * 0 0 0 0 0 0 0 0 0 0

0 0 0 0 * 0 0 0 0 0 0 0 0 0 0

0 0 0 0 * 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Generation 1

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 * * * 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Generation 2

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

0 0 0 0 * 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