您的位置:首页 > 其它

hdu 4772 Zhuge Liang's Password(水题)

2014-07-06 19:49 260 查看
题目连接:hdu 4772 Zhuge Liang's Password

题目大意:给出两个n*n的矩阵,可以旋转矩阵,求两个矩阵重叠位置数值相同的位置最多为多少。

解题思路:水题,写一个矩阵旋转,然后暴力判断。
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 30;

int n, a[2][maxn][maxn];

int solve () {
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[0][i][j] == a[1][i][j])
cnt++;
}
}
return cnt;
}

void role(int b[maxn][maxn]) {
int c[maxn][maxn];

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
c[j][n-i-1] = b[i][j];
}
}
memcpy(b, c, sizeof(c));
}

int main () {
while (scanf("%d", &n) == 1 && n) {
for (int k = 0; k < 2; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
scanf("%d", &a[k][i][j]);
}
}

int ans = 0;
for (int i = 0; i < 4; i++) {
ans = max(ans, solve());
role(a[0]);
}
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: