# USACO Section 1.2.3 Transformations

## 题目

Transformations

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:

• #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
• #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
• #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
• #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
• #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
• #6: No Change: The original pattern was not changed.
• #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

In the case that more than one transform could have been used, choose the one with the minimum number above.

### INPUT FORMAT

 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

### SAMPLE INPUT (file transform.in)

3
@[email protected]
---
@@-
@[email protected]
@--
[email protected]


### OUTPUT FORMAT

A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the before' representation to the after' representation.

### SAMPLE OUTPUT (file transform.out)

1


## 代码

/*
ID:zhrln1
PROG:transform
LANG:C++
*/
#include <cstdio>
int n;
typedef struct board{
char v[11][11];
} Board;
Board a,b;
Board rdboard(int n){
Board c;
for (int i(1);i<=n;i++){
for (int j(1);j<=n;j++){
scanf("%c",&c.v[i][j]);
}
scanf("\n");
}
return c;
}
Board change(Board a,int k,int n){
Board c;
for (int i(1);i<=n;i++){
for (int j(1);j<=n;j++){
switch(k){
case 1: c.v[i][j]=a.v[n-j+1][i];break;
case 2: c.v[i][j]=a.v[n+1-i][n+1-j];break;
case 3: c.v[i][j]=a.v[j][n+1-i];break;
case 4: c.v[i][j]=a.v[i][n+1-j];break;
}
}
}
return c;
}
int isequel(Board a,Board b,int n){
for (int i(1);i<=n;i++){
for (int j(1);j<=n;j++){
if (a.v[i][j]!=b.v[i][j]) return 0;
}
}
return 1;
}
int main(){
freopen("transform.in","r",stdin);
freopen("transform.out","w",stdout);
scanf("%d\n",&n);
a=rdboard(n);
b=rdboard(n);
for (int i(1);i<=4;i++){
Board t=change(a,i,n);
if (isequel(t,b,n)){
printf("%d\n",i);
return 0;
}
if (i==4){
for (int j(1);j<=3;j++){
if (isequel(change(t,j,n),b,n)){
printf("5\n");
return 0;
}
}
}
}
if (isequel(a,b,n)){
printf("6\n");
return 0;
}
printf("7\n");
return 0;
}