# 星星灰暗着。

### 题解 P1205 【[USACO1.2]方块转换 Transformations】

posted on 2017-08-18 09:51:50 | under 题解 |

#include<cstdio>
#include<iostream>
#define f(i,a,b) for(register int i=a;i<=b;++i)
int n;
char a[20][20],s[20][20],b[20][20];
void turn()
{
f(i,0,n-1)
f(j,0,n-1)
b[i][j]=a[i][j];
f(i,0,n-1)
f(j,0,n-1)
a[i][j]=b[n-1-j][i];
}
void mirror()
{
f(i,0,n-1)
f(j,0,n-1)
b[i][j]=a[i][j];
f(i,0,n-1)
f(j,0,n-1)
a[i][j]=b[i][n-1-j];
}
void check()//检验转换是否正确
{
f(i,0,n-1)puts(a[i]);
}
bool compare()
{
f(i,0,n-1)
f(j,0,n-1)
if(a[i][j]!=s[i][j])return 0;
return 1;
}
int main()
{
int i,j;
scanf("%d",&n);
getchar();
f(i,0,n-1)scanf("%s",a[i]);
f(i,0,n-1)scanf("%s",s[i]);
turn();if(compare()){printf("1\n");return 0;}
turn();if(compare()){printf("2\n");return 0;}
turn();if(compare()){printf("3\n");return 0;}
turn();mirror();//还原,镜像
if(compare()){printf("4\n");return 0;}
turn();if(compare()){printf("5\n");return 0;}
turn();if(compare()){printf("5\n");return 0;}
turn();if(compare()){printf("5\n");return 0;}
turn();if(compare()){printf("6\n");return 0;}
printf("7\n");return 0;
}