AcWing 3527. 旋转矩阵
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 20;
int t, n, m, k, l, r, op, x, y;
int f[N][N], f2[N][N];
bool flag;
void print(){
for(int i = 1;i<=n;i++){
for(int j = 1;j<=n;j++){
cout<<f[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n";
}
void zhuan() {
for (int i = 1; i <= (n+1)/2; i++) {
for (int j = i; j <= n-i; j++) {
int mi = i, mj = j;
t = f[mi][mj];
while (true) {
f[mi][mj] = f[n + 1 - mj][mi];
if(n+1-mj==i&&mi==j){
break;
}
x = mi;
mi = n + 1 - mj;
mj = x;
}
f[mi][mj] = t;
// print();
}
}
}
bool equ() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (f[i][j] != f2[i][j]) {
return false;
}
}
}
return true;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> f[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> f2[i][j];
}
}
k = 0;
for (; k < 4; k++) {
if (equ()) {
flag = true;
break;
}
zhuan();
// print();
}
if (flag) {
cout << 90 * k << "\n";
} else {
cout << -1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}