137 - ZOJ Monthly, November 2014 - I
Bob is recently playing a game called Minecraft, especially a mod called Thaumcraft. It is a mod of magic.
Usually, Bob has Obsessions with Symmetry while playing Minecraft. This obsession is useless in the gameplay generally. However, in Thaumcraft, the infusion altar requires symmetry to keep it stable.
Bob built an infusion altar in his secret chamber, but it was not so symmetrical. After some explosions, Bob decided to fix the infusion altar to make it symmetrical.
You will be given the map of Bob's secret chamber. It is of size n*n(n is an odd number), the infusion altar is always at the center of his secret chamber. The following picture is a typical map. The 3*3 square in the center is the Infusion Altar, it is a multi-block structure. Here, '#' means Runic Matrix, 'o' means Arcane Pedestal, '.' means an empty place, 'a'-'z' means occult paraphernalia(like skulls, crystals and candles) Bob placed around the Infusion Altar. There will not be characters other than 'a'-'z', '.', '#'.
.aab. bo.ob b.#.a bo.ob bbab.
Now, the question is that at least how many blocks need to be changed to make the whole map symmetrical. Here, being symmetrical means having all four axes of symmetry for a square. Also, you can change any character on the map to any other character.
There are multiple cases. The first line contains one integer T which is the number of test cases.
One integer for each test case which is the least number of blocks that should be changed.
3 3 o.o .#. o.o 5 .aab. bo.ob b.#.a bo.ob bbab. 5 aabba ao.oa a.#.a ao.oa aaaaa
0 3 2
The first sample is a standard Infusion Altar.
.bab. bo.ob a.#.a bo.ob .bab.
Author: ZHU, Jiale; GONG, Yuan