-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcan_matrix_obtained_by_turning.cpp
69 lines (65 loc) · 1.33 KB
/
can_matrix_obtained_by_turning.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
void turn(vector<vector<int>> &vec)
{
int p = vec.size();
vector<vector<int>> result;
for (int i = 0; i < p; i++)
{
vector<int> v;
for (int j = p - 1; j >= 0; j--)
{
v.push_back(vec[j][i]);
}
result.push_back(v);
}
vec = result;
}
bool findRotation(vector<vector<int>> &mat, vector<vector<int>> &target)
{
if (mat == target)
return true;
int num = 3;
while (num)
{
turn(mat);
if (mat == target)
return true;
num--;
}
return false;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int r;
cin >> r;
vector<vector<int>> nums, target;
for (int i = 0; i < r; i++)
{
vector<int> v;
for (int j = 0; j < r; j++)
{
int temp;
cin >> temp;
v.push_back(temp);
}
nums.push_back(v);
}
for (int i = 0; i < r; i++)
{
vector<int> v;
for (int j = 0; j < r; j++)
{
int temp;
cin >> temp;
v.push_back(temp);
}
target.push_back(v);
}
cout << findRotation(nums, target) << endl;
}
}