Drop7
Time limit1sMemory limit128 MB
Simulate n disc drops on a 7 by 7 board with simultaneous number-match eliminations and gravity, then print the final board.
- Level
Medium5 of 10
- Topics
- Simulation, Matrix
- Solved
- No attempts yet
Problem
Drop7 is a single player game on a vertical grid. The grid starts empty. On each turn you are handed a disc with a number from 1 to 7 written on it, and you drop it into one of the seven columns from above. The disc falls down the chosen column and stops on top of the highest disc already in that column. If the column is empty, the disc reaches the floor and stays in the bottom row.
After the drop, every disc whose number equals the size of its group column or the size of its group row disappears. All of them fade at the same moment. Then every disc that lost the disc under it falls straight down as far as it can. The condition is checked again over all remaining discs, and the loop repeats until no disc matches. Once nothing else disappears, the next turn begins.
The group column of a disc is the number of discs stacked in the same column, counting the disc itself. Say a column holds 7 and 7 from the bottom and you drop a 3 on top: the column now holds three discs, so the 3 disappears and the two 7s stay. One drop can also start a chain. Say a column holds 5, 5, 4 from the bottom and you drop a 3 on top. The column size is 4, so the 4 disappears first. The 3 then falls onto the two 5s, the column size becomes 3, and the 3 disappears as well.
The group row of a disc is the number of discs that sit side by side with no gap in the same row, counting the disc itself. If a row holds a 3 next to another 3 and a disc lands in the cell beside them so that three cells run together, both 3s have group row size 3 and they disappear at once.
You start from an empty board and receive the drops of one game. Simulate the game and print the final state of the board.
Input
The input holds several test cases. The first line of each test case holds (), the number of discs dropped. Each of the next lines holds two integers and (), meaning that on turn the disc numbered is dropped into column . Columns are numbered 1 to 7 from the left. The line after the last test case holds a single 0.
Output
For each test case print seven lines of seven characters. The first line is the top row of the grid and the seventh line is the bottom row. A cell holding a disc prints that disc's number, and an empty cell prints a hash sign (#).
If a disc is dropped into a column that already holds seven discs, the test case prints the single line Game Over! instead of the grid. The remaining drops of that test case are read but not played.
Print one blank line between the outputs of two consecutive test cases. Do not print a blank line after the last test case.