hdu 4772 Zhuge Liang's Password
阿新 • • 發佈:2019-02-01
題意:給定兩個n*n的矩陣,矩陣可以進行90,180,270的旋轉,問兩個矩陣完全重合的時候最多有幾個數是相同的
思路:暴力列舉第一個矩陣的4種情況和第二個矩陣匹配,求出ans
程式碼:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int MAXN = 310; int n; int mat[MAXN][MAXN]; int mp[MAXN][MAXN]; int tmp[MAXN][MAXN]; void getTmp(){ int pos = 0; memcpy(mat , tmp , sizeof(tmp)); for(int i = n-1 ; i >= 0 ; i-- , pos++) for(int j = 0 ; j < n ; j++) tmp[pos][j] = mat[j][i]; } int getCnt(){ int cnt = 0; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < n ; j++) if(tmp[i][j] == mp[i][j]) cnt++; } return cnt; } int solve(){ int ans = 0; memcpy(tmp , mat , sizeof(tmp)); // 0 ans = max(ans , getCnt()); // 90 getTmp(); ans = max(ans , getCnt()); // 1800 getTmp(); ans = max(ans , getCnt()); // 270 getTmp(); ans = max(ans , getCnt()); return ans; } int main(){ while(scanf("%d" , &n) && n){ for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++) scanf("%d" , &mat[i][j]); for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++) scanf("%d" , &mp[i][j]); printf("%d\n" , solve()); } return 0; }