题目大意:
已知一个初始矩阵和一个目标矩阵还有几种操作,问起始矩阵经过那种操作可以得到目标矩阵。
思路:
模拟题,思路见注释。唯一需要注意的是判断操作需要按照题目所给顺序进行。
代码:
/*
ID: lujunda1
LANG: C++
PROG: transform
*/
#include
#include
#include
#include
#include
using namespace std;
int n;
//判断a[][]与a[][]是否相等
bool equ(char a[][11],char b[][11])
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(a[i][j]!=b[i][j])
return false;
return true;
}
//判断a[][]顺时针旋转90°后是否等于b[][]
bool rotation_1(char a[][11],char b[][11])
{
char temp[11][11];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
temp[i][j]=a[j][n-1-i];
if(equ(temp,b))
return true;
return false;
}
//判断a[][]顺时针旋转180°后是否等于b[][]
bool rotation_2(char a[][11],char b[][11])
{
char temp[11][11];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
temp[i][j]=a[n-1-i][n-1-j];
if(equ(temp,b))
return true;
return false;
}
//判断a[][]顺时针旋转270°后是否等于b[][]
bool rotation_3(char a[][11],char b[][11])
{
char temp[11][11];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
temp[i][j]=a[n-1-j][i];
if(equ(temp,b))
return true;
return false;
}
//b[][]镜面反射后的结果赋值给a[][]
void reflect(char a[][11],char b[][11])
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
a[i][j]=b[i][n-1-j];
}
//判断a[][]做镜面处理后是否与b[][]相等
bool reflection(char a[][11],char b[][11])
{
char temp[11][11];
reflect(temp,a);
if(equ(temp,b))
return true;
return false;
}
//判断a[][]做镜面处理后再旋转后是否与b[][]相等
bool combination(char a[][11],char b[][11])
{
char temp[11][11];
reflect(temp,a);
if(rotation_1(temp,b)||rotation_2(temp,b)||rotation_3(temp,b))
return true;
return false;
}
void check(char before[][11],char after[][11])
{
if(rotation_1(before,after))
printf("1\n");
else if(rotation_2(before,after))
printf("2\n");
else if(rotation_3(before,after))
printf("3\n");
else if(reflection(before,after))
printf("4\n");
else if(combination(before,after))
printf("5\n");
else if(equ(before,after))
printf("6\n");
else
printf("7\n");
}
int main()
{
freopen("transform.in","r",stdin);
freopen("transform.out","w",stdout);
scanf("%d",&n);
char before[11][11],after[11][11];
for(int i=0;i<n;i++)
scanf("%s",before[i]);
for(int i=0;i<n;i++)
scanf("%s",after[i]);
check(before,after);
}