Population Explosion: Input
Population Explosion: Input
You just received a call from NASA’s chief scientist who is working on a habitable structure to be built
on the moon. He has designed various models of enclosed cities that people could live in, but he is unsure
as to how these models will stand up to population growth. Therefore, since your name has become
synonymous with “He Can Program Anything From Neat, Flashy Space Games That Entangle You
For Hours To Highly Sophisticated Super Spy Surveillance Satellite Image Enhancement Algorithms,”
he immediately called you with his problem. Here is what he said:
“I need a program which will read in a set of data points that represent the location of living quarters
within the city. I then want the program to simulate the creation, growth, and death of each living
quarter per year based on the following rules:
1. Every living quarter with two or three neighboring quarters survives the current year.
2. Each living quarter with four or more neighbors dies due to over-population. Each living quarter
with one or less neighbors dies from isolation.
3. Each empty location that is adjacent to exactly three neighbors — no more, no fewer — will have
someone build new living quarters in that location for the next year.
Note that each living quarter can have from zero to eight adjacent neighbors (i.e. north, south,
east, west, north-west, north-east, south-west, and south-east) at any given time.
Each city model will have a maximum of 20 possible living quarters in the north-south direction
and 20 in the east-west direction. The top left corner will be designated location 1,1 (N-S position,
E-W position) and the bottom right is therefore 20,20. Any questions?”
“Yes, one,” you replied, “What will the input file look like?”
Input
“The input begins with a single positive integer on a line by itself indicating the number of the cases
following, each of them as described below. This line is followed by a blank line, and there is also a
blank line between two consecutive inputs.”
“Let the first line of each input specify the number of years to run the simulation. Then, following
that will be the coordinates for the initial locations.”
Output
“For each test case, I want the program to read the data file and then output the existing population
map for each year.
Year 1 will correspond to the initial configuration. Therefore, the first map in the file should be the
inital configuration. Mark empty locations with a space and living quarters with a capital letter ‘O’.
Please separate each year’s output with a single line of 20 asterisks, and put a similar line both as
the first and the last of the output file.”
Universidad de Valladolid OJ: 447 – Population Explosion 2/3
Sample Input
1
3
5 4
5 5
5 6
5 7
Sample Output
********************
OOOO
********************
OO
OO
OO
Universidad de Valladolid OJ: 447 – Population Explosion 3/3
********************
OO
O O
OO
********************