# HDU 4772 --Zhuge Liang's Password

2013ACM亚洲区杭州站现场赛1003

/**
test cases:
3
1 1 1
2 2 2
3 3 3
3 2 1
3 2 1
3 2 1

//ans=9
*/

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int a[31][31];
int b[31][31];
int temp[31][31];

int compare(int n)
{
int ans = 0;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
if(temp[i][j] == a[i][j]) ans++;
}
}
return ans;
}

void roll_90(int n)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
temp[i][j] = b[n-j-1][i];
}
}
void roll_180(int n)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
temp[i][j] = b[n-i-1][n-j-1];
}
}

void roll_270(int n)
{
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
temp[i][j] = b[j][n-i-1];
}
}

int main()
{
int n;
while(scanf("%d",&n),n)
{
int ans = 0;
int MAX = -32766;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
scanf("%d",&a[i][j]);
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
scanf("%d",&b[i][j]);
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
temp[i][j] = b[i][j];
}
ans = compare(n);
MAX = ans;
roll_90(n);
ans = compare(n);
if(ans > MAX) MAX = ans;
roll_180(n);
ans = compare(n);
if(ans > MAX) MAX = ans;
roll_270(n);
ans = compare(n);
if(ans > MAX) MAX = ans;
printf("%d\n",MAX);
}
return 0;
}



#### HDU 4772 Zhuge Liang's Password 矩阵旋转

2014-10-11 20:29:39

#### Hdu 4772 Zhuge Liang's Password

2013-11-16 16:22:12

#### HDU 4772 Zhuge Liang's Password

2014-11-15 22:30:41

#### HDU 4772 Zhuge Liang's Password

2013-11-24 22:33:24

#### hdu 4772 Zhuge Liang's Password

2013-11-13 17:05:04

#### HDU 4772 Zhuge Liang's Password（模拟）

2017-12-27 23:57:44

#### HDU 4772 Zhuge Liang's Password 水

2014-11-14 20:41:32

#### HDU 4772 Zhuge Liang's Password（暴力）

2016-06-08 15:02:40