提交时间:2025-03-14 15:07:11

运行 ID: 7161

#include <iostream> using namespace std; const int MAX = 1001; // 最大允许矩阵尺寸 bool pd(int a[][MAX], int b[][MAX], int n) { bool match[4] = {true, true, true, true}; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { // 同时检查四个旋转方向 if (a[i][j] != b[i][j]) match[0] = false; // 0° if (a[i][j] != b[j][n-1-i]) match[1] = false; // 90° if (a[i][j] != b[n-1-i][n-1-j]) match[2] = false; // 180° if (a[i][j] != b[n-1-j][i]) match[3] = false; // 270° // 提前终止检查 if (!(match[0] || match[1] || match[2] || match[3])) return false; } } return match[0] || match[1] || match[2] || match[3]; } int main() { int n,m; cin>>m; while (m--){ int a[MAX][MAX], b[MAX][MAX]; cin>>n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin>>a[i][j]; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin>>b[i][j]; } } if (pd(a,b,n)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }