题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4772
思路: 直接暴力 把四种角度全部列举出来,然后逐一看重合个数有多少
代码:
#include<iostream>
#include<cstdio>
using namespace std;
struct Matrix
{
int a[30][30];
};
Matrix right_turn(Matrix x,int n)
{
Matrix ans;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
ans.a[i][j]=x.a[n-1-j][i];
}
return ans;
}
int password(Matrix A,Matrix B,int n)
{
int ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(A.a[i][j]==B.a[i][j])
ans++;
}
return ans;
}
int main()
{
int n;
while(cin>>n)
{
if(n==0) break;
Matrix m[5];
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&m[1].a[i][j]);
for(int i=2;i<=4;i++)
m[i]=right_turn(m[i-1],n);
Matrix m5;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
scanf("%d",&m5.a[i][j]);
int overlap[4];
for(int i=0;i<4;i++)
overlap[i]=password(m5,m[i+1],n);
int max=0;
for(int i=0;i<4;i++)
if(overlap[i]>max)
{
max=overlap[i];
}
cout<<max<<endl;
}
}