-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix_similarity_cyclic_shift.cpp
77 lines (75 loc) · 1.69 KB
/
matrix_similarity_cyclic_shift.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
70
71
72
73
74
75
76
77
static const int __ = []() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
return 0;
}();
class Solution {
public:
bool areSimilar(vector<vector<int>> &mat, int k) {
int i, j, m;
int n = mat.size();
int nr = mat[0].size();
cout << n << endl;
cout << nr << endl;
vector<vector<int>> ans;
unordered_map<int, int> cnt;
int tempo, tempn;
for (i = 0; i < n; i++) {
cnt[i] = 0;
}
vector<int> arr, arr1;
for (i = 0; i < n; i++) {
arr.clear();
for (j = 0; j < nr; j++) {
arr.push_back(mat[i][j]);
}
while (cnt[i] < k) {
if (i % 2 == 1) {
tempn = arr[nr - 1];
for (m = 0; m < arr.size(); m++) {
if (m == 0) {
tempo = arr[m];
arr[m] = tempn;
} else {
tempo = arr[m];
arr[m] = tempn;
// arr[i] = temp;
}
tempn = tempo;
}
} else {
tempn = arr[0];
for (m = nr - 1; m >= 0; m--) {
if (m == nr - 1) {
tempo = arr[m];
arr[m] = tempn;
} else {
tempo = arr[m];
arr[m] = tempn;
// arr[i] = temp;
}
tempn = tempo;
}
}
for (m = 0; m < nr; m++) {
cout << arr[m] << "\t";
}
cout << endl;
cnt[i]++;
}
ans.push_back(arr);
}
// for(i=0; i<n; i++){
// for(j=0; j<nr; j++){
// cout<<ans[i][j]<<"\t";
// }
// cout<<endl;
// }
if (ans == mat) {
return true;
} else {
return false;
}
}
};