Zoj 3838 infusion altar ?)

Source: Internet
Author: User

Question link: http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemid = 5412


Bob is recently Playing a game calledMinecraft, Especially a mod calledThaumcraft. It is a mod of magic.

Usually, Bob has obsessions with interval ry while playingMinecraft. This obsession is useless in the gameplay generally. However, inThaumcraft, The infusion altar requires failed ry to keep it stable.

Bob built an infusion altar in his secret chamber, but it was not so defined rical. After some explosions, Bob decided to fix the infusion altar to make it ready rical.

You will be given the map of Bob's secret chamber. It is of sizeN*N(NIs 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 pede ,'. '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.obb.#.abo.obbbab.

Now, the question is that at least how many blocks need to be changed to make the whole map contains rical. Here, being has rical means havingAll four axesOf every ry 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 integerTWhich is the number of test cases.
For each case, the first line contains an integerN(3 ≤N≤ 99, andNIs an odd number)
For the nextNLines, 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 shocould be changed.

Sample Input
33o.o.#.o.o5.aab.bo.obb.#.abo.obbbab.5aabbaao.oaa.#.aao.oaaaaaa
Sample output
032
Hint

The first sample is a standard infusion altar.
In second sample, Bob will change his secret chamber to the following map.

.bab.bo.oba.#.abo.ob.bab.
Author: Zhu, jiale; Gong, Yuan

Source: zoj monthly, November 2014

Question:

Find the minimum number of operations to make the image symmetric!


PS:


1. First, find the minimum number of operations to make the four symmetric and axial symmetry (obviously, you only need to find a red line and half of a white line respectively to make the eight parts the same );

2. enumerate 1, 2, 3 ...... The number of grids is the same as the remaining seven grids!



The Code is as follows: (have you ever seen this frustrating code ?)

# Include <cstdio> # include <cstring> # include <cmath> int main () {int t; int N; char s [117] [117]; scanf ("% d", & T); While (t --) {scanf ("% d", & N); For (INT I = 0; I <N; I ++) {scanf ("% s", s [I]);} int M = n/2; int sum = 0; int Minn; char tt; for (INT I = 0; I <m; I ++) // midline {Minn = 4; TT = s [I] [m]; // 1 int k1 = 0; If (TT! = S [m] [I]) k1 ++; If (TT! = S [n-1-i] [m]) k1 ++; If (TT! = S [m] [n-1-i]) k1 ++; If (Minn> k1) Minn = k1; TT = s [m] [I]; // 2 int k2 = 0; If (TT! = S [I] [m]) K2 ++; If (TT! = S [n-1-i] [m]) K2 ++; If (TT! = S [m] [n-1-i]) K2 ++; If (Minn> k2) Minn = k2; TT = s [n-1-i] [m]; // 3 int K3 = 0; If (TT! = S [m] [I]) K3 ++; If (TT! = S [I] [m]) K3 ++; If (TT! = S [m] [n-1-i]) K3 ++; If (Minn> K3) Minn = K3; TT = s [m] [n-1-i]; // 4 int K4 = 0; If (TT! = S [m] [I]) K4 ++; If (TT! = S [n-1-i] [m]) K4 ++; If (TT! = S [I] [m]) K4 ++; If (Minn> K4) Minn = K4; sum + = Minn ;}for (INT I = 0; I <m; I ++) // the diagonal line of the primary pair {Minn = 4; TT = s [I] [I]; // 1 int k1 = 0; If (TT! = S [n-1-i] [n-1-i]) k1 ++; If (TT! = S [n-1-i] [I]) k1 ++; If (TT! = S [I] [n-1-i]) k1 ++; If (Minn> k1) Minn = k1; TT = s [n-1-i] [n-1-i]; // 2 int k2 = 0; If (TT! = S [I] [I]) K2 ++; If (TT! = S [n-1-i] [I]) K2 ++; If (TT! = S [I] [n-1-i]) K2 ++; If (Minn> k2) Minn = k2; TT = s [n-1-i] [I]; // 3 int K3 = 0; If (TT! = S [n-1-i] [n-1-i]) K3 ++; If (TT! = S [I] [I]) K3 ++; If (TT! = S [I] [n-1-i]) K3 ++; If (Minn> K3) Minn = K3; TT = s [I] [n-1-i]; // 4 int K4 = 0; If (TT! = S [n-1-i] [n-1-i]) K4 ++; If (TT! = S [n-1-i] [I]) K4 ++; If (TT! = S [I] [I]) K4 ++; If (Minn> K4) Minn = K4; sum + = Minn ;}// printf ("sum :: % d \ n ", sum); // int CEN = (n/2) * (N/2)-(n/2)/2; int CEN = n/2; // printf ("CEN: % d \ n", CEN); For (INT I = 0; I <cen-1; I ++) {int cc = 0; For (Int J = I + 1; j <CEN; j ++) {Minn = 8; TT = s [I] [J]; // 1 // printf ("s [I] [J]: % C \ n", s [I] [J]); CC = 0; If (TT! = S [J] [I]) CC ++; // printf ("s [I] [J]: % C \ n ", s [J] [I]); If (TT! = S [I] [n-1-j]) CC ++; // printf ("s [I] [n-1-j]: % C \ n ", s [I] [n-1-j]); If (TT! = S [n-1-j] [I]) CC ++; // printf ("s [n-1-j] [I]: % C \ n ", s [n-1-j] [I]); If (TT! = S [J] [n-1-i]) CC ++; // printf ("s [J] [n-1-i]: % C \ n ", s [J] [n-1-i]); If (TT! = S [n-1-i] [J]) CC ++; // printf ("s [n-1-i] [J]: % C \ n ", s [n-1-i] [J]); If (TT! = S [n-1-j] [n-1-i]) CC ++; // printf ("s [n-1-j] [n-1-i]: % C \ n ", s [n-1-j] [n-1-i]); If (TT! = S [n-1-i] [n-1-j]) CC ++; // printf ("s [n-1-i] [n-1-j]: % C \ n ", s [n-1-i] [n-1-j]); If (CC <Minn) Minn = cc; TT = s [J] [I]; // 2 cc = 0; If (TT! = S [I] [J]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [I] [n-1-j]; // 3 cc = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [J]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [n-1-j] [I]; // 4 cc = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [I] [J]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [J] [n-1-i]; // 5 cc = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [I] [J]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [n-1-i] [J]; // 6 cc = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [I] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [n-1-j] [n-1-i]; // 7 CC = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [I] [J]) CC ++; If (TT! = S [n-1-i] [n-1-j]) CC ++; If (CC <Minn) Minn = cc; TT = s [n-1-i] [n-1-j]; // 8 cc = 0; if (TT! = S [J] [I]) CC ++; If (TT! = S [I] [n-1-j]) CC ++; If (TT! = S [n-1-j] [I]) CC ++; If (TT! = S [J] [n-1-i]) CC ++; If (TT! = S [n-1-i] [J]) CC ++; If (TT! = S [n-1-j] [n-1-i]) CC ++; If (TT! = S [I] [J]) CC ++; If (CC <Minn) Minn = cc; sum + = Minn ;}} printf ("% d \ n ", sum);} return 0;}/* 993o. o. #. o. o5.aab. bo. OBB. #. abo. obbbab.5aabbaao. OAA. #. AAO. oaaaaaa55.1a2.3o. o4b. #. a5o. o6b7a8. */


Zoj 3838 infusion altar ?)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.