forked from yalza/CPP_code.ptit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPP0228 - IN MA TRẬN - 2
52 lines (51 loc) · 1.16 KB
/
CPP0228 - IN MA TRẬN - 2
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
#include<iostream>
using namespace std;
int main() {
int t; cin >> t;
while (t--) {
int n; cin >> n;
int M[100][100];
int a = 1;
for (int i = 1; i <= 4 * n; i++)
for (int j = 1; j <= 4 * n; j++)
M[i][j] = a++;
int x = 4 * n;
int N[10000];
int gt = 0;
for (int j = 1; j <= 4*n; j+=2) {
for (int i = j; i <= x; i++)
N[gt++] = M[i][j];
for (int i = j + 1; i < x; i++)
N[gt++] = M[x][i];
for (int i = x - 1; i > j; i--)
N[gt++] = M[i][x - 1];
for (int i = x - 2; i > j + 1; i--)
N[gt++] = M[j + 1][i];
x = x - 2;
}
int b = 4 * 4 * n * n;
int A[10000];
int g = 0;
x = 4 * n;
for (int i = 1; i <= 4 * n; i++)
for (int j = 1; j <= 4 * n; j++)
M[i][j] = b--;
for (int j = 1; j <= 4 * n; j += 2) {
for (int i = j; i <= x; i++)
A[g++] = M[i][j];
for (int i = j + 1; i < x; i++)
A[g++] = M[x][i];
for (int i = x - 1; i > j; i--)
A[g++] = M[i][x - 1];
for (int i = x - 2; i > j + 1; i--)
A[g++] = M[j + 1][i];
x = x - 2;
}
for (int i = gt - 1; i >= 0; i--)
cout << A[i] << " ";
cout << endl;
for (int i = gt - 1; i >= 0; i--)
cout << N[i] << " ";
cout << endl;
}
}