# ZOJ-3838-Infusion Altar

## Infusion Altar

                            Time Limit: 2 Seconds      Memory Limit: 65536 KB


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.

InfusionAltar
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.

Input

There are multiple cases. The first line contains one integer T which is the number of test cases.
For each case, The first line contains an integer n ( 3 ≤ n ≤ 99, and n is an odd number)
For the next n lines, each line contains n characters showing the map.
It is guaranteed that the Infusion Altar is at the center of the map.
It is guaranteed that only ‘a’-‘z’ and ‘.’ will appear out of the Infusion Altar.

Output
One integer for each test case which is the least number of blocks that should be changed.
Sample Input
3
3
o.o
.#.
5
.aab.
bo.ob
b.#.a
bo.ob
bbab.
5
aabba
ao.oa
a.#.a
ao.oa
aaaaa
Sample Output
0
3
2
Hint
The first sample is a standard Infusion Altar.
In second sample, Bob will change his secret chamber to the following map.
.bab.
bo.ob
a.#.a
bo.ob
.bab.

o.o

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
string s[110];
int ans = 0,cnt = 0;
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n / 2; i++)
{
for (int j = 0; j < n / 2; j++)
{
if (i > j)              //处理圆圈处，对称8个相等
{
cnt = 1;
int maxcnt = 1;
string ret = "";
ret += s[i][j];
ret += s[j][i];
ret += s[n - 1 - i][j];
ret += s[j][n - i - 1];
ret += s[i][n - 1 - j];
ret += s[n - 1 - j][i];
ret += s[n - 1 - i][n - 1 - j];
ret += s[n - 1 - j][n - 1 - i];
sort(ret.begin(),ret.end());
for (int i = 0;i < 7; i++)
{
if (ret[i] == ret[i + 1])
{
cnt++;
maxcnt = max(cnt,maxcnt);
}
else
cnt = 1;
}
ans += 8 - maxcnt;
}
else if (i == j)      //处理对角线
{
cnt = 1;
int maxcnt = 1;
string ret = "";
ret += s[i][j];
ret += s[i][n - j - 1];
ret += s[n - i - 1][j];
ret += s[n - i - 1][n - j - 1];
sort(ret.begin(),ret.end());
for (int i = 0;i < 3; i++)
{
if (ret[i] == ret[i + 1])
{
cnt++;
maxcnt = max(cnt,maxcnt);
}
else
cnt = 1;
}
ans += 4 - maxcnt;
}
}
}
int i = (n - 1) / 2;         //处理另外两条直线
for (int j = 0; j < n / 2; j++)
{
cnt = 1;
int maxcnt = 1;
string ret = "";
ret += s[i][j];
ret += s[i][n - j - 1];
ret += s[j][i];
ret += s[n - j - 1][i];
sort(ret.begin(),ret.end());
for (int i = 0;i < 3; i++)
if (ret[i] == ret[i + 1])
{
cnt++;
maxcnt = max(maxcnt,cnt);
}
else
cnt = 1;
ans += 4 - maxcnt;
}
cout << ans << endl;
}
return 0;
}

#### 寻迹小车寻迹c程序源代码

2009年08月07日 4KB 下载

#### 寻迹小车——代码

2016-09-20 22:09:51

#### Modular_SGDMA_DE

2015年03月25日 420KB 下载

#### zoj 3838 Infusion Altar

2014-11-30 21:50:32

#### ZOJ3838 - Infusion Altar(找规律模拟)

2014-11-30 21:40:12

#### 【水题】 ZOJ 3838 Infusion Altar

2014-11-30 18:05:21

2017-03-29 00:11:34

#### ZOJ 3838 Infusion Altar（数学啊 模拟啊 这么挫的代码你见过吗？）

2014-11-30 18:13:21

#### 考研英语易混词汇对照

2009年02月23日 54KB 下载