A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:
In the case that more than one transform could have been used, choose the one with the minimum number above.
Line 1: | A single integer, N |
Line 2..N+1: | N lines of N characters (each either `@' or `-'); this is the square before transformation |
Line N+2..2*N+1: | N lines of N characters (each either `@' or `-'); this is the square after transformation |
3 @-@ --- @@- @-@ @-- --@
1
/* ID:qhn9992 PROG:transform LANG:C++11 */ #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <set> #include <queue> using namespace std; const int INF=0x3f3f3f3f; int n; struct tu { char m[11][11]; int t; }A,B; tu Rotation90(tu C) { tu X; X.t=C.t; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { X.m[i][j]=C.m[n-j-1][i]; } } return X; } tu Rotation180(tu C) { tu X; X.t=C.t; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { X.m[i][j]=C.m[n-i-1][n-j-1]; } } return X; } tu Rotation270(tu C) { tu X; X.t=C.t; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { X.m[i][j]=C.m[j][n-i-1]; } } return X; } tu Reflection(tu C) { tu X; X.t=C.t; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { X.m[i][j]=C.m[i][n-j-1]; } } return X; } tu Combination90(tu C) { return Rotation90(Reflection(C)); } tu Combination180(tu C) { return Rotation180(Reflection(C)); } tu Combination270(tu C) { return Rotation270(Reflection(C)); } int CMP(tu a,tu b) { int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a.m[i][j]!=b.m[i][j]) ans++; } } return ans; } int main() { freopen("transform.in","r",stdin); freopen("transform.out","w",stdout); int ans=0,ans2=INF; scanf("%d",&n); memset(A.m,0,sizeof(A.m)); memset(B.m,0,sizeof(B.m)); for(int i=0;i<n;i++) scanf("%s",A.m[i]);A.t=0; for(int i=0;i<n;i++) scanf("%s",B.m[i]);B.t=0; int ANS=7; if(CMP(B,Rotation90(A))==0) { ANS=1; } else if(CMP(B,Rotation180(A))==0) { ANS=2; } else if(CMP(B,Rotation270(A))==0) { ANS=3; } else if(CMP(B,Reflection(A))==0) { ANS=4; } else if(CMP(B,Combination90(A))==0||CMP(B,Combination180(A))==0||CMP(B,Combination270(A))==0) { ANS=5; } else if(CMP(A,B)==0) { ANS=6; } else ANS=7; printf("%d\n",ANS); return 0; }