Canadian Computing Competition: 2009 Stage 2, Day 2, Problem 2
May 9 is VE day, when the annual victory parade is held through Red Square. Inspired by the award ceremony of the 2009 ACM World Finals, you have decided to recreate the original VE day parade digitally. Since you have skillfully obtained all the necessary hardware, the most difficult part remaining is to track the configuration of a single formation.
A formation can be viewed as a 4-by-4 array, with the people initially labelled 1 through 16:
Then a sequence of commands
Rotate all people on the perimeter of a
-by- square with its upper left corner located at row , column clockwise by one position.
For example, the command
As another example,
A third example,
You have obtained the original sequence of commands issued. However, you are not quite pleased with the final result and would like to edit some of the commands. Support
Change the
th command to , and permanently.
Furthermore, you would like to see the effects of your change immediately. After each change, output what the formation would look like at the end of all
For
Input Specification
The first line contains two integers
The next
The next
Output Specification
For each change, print 4 lines, the final configuration of the formation after the modifications so far.
Sample Input
2 4
1 1 1
1 1 1
1 1 1 2
2 2 2 3
1 1 1 1
2 1 1 4
Output for Sample Input
5 1 3 4
6 2 7 8
9 10 11 12
13 14 15 16
5 1 3 4
6 10 2 7
9 14 11 8
13 15 16 12
1 2 3 4
5 10 6 7
9 14 11 8
13 15 16 12
5 1 2 3
9 6 7 4
13 10 11 8
14 15 16 12
Description of Output for Sample Input
The two commands
The second change takes this configuration and applies
The next change alters the first change to be the "original" graph, and then, since the second command has been changed to
The last change causes the second command to be
Comments