-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1520c.cpp
More file actions
65 lines (60 loc) · 1.13 KB
/
1520c.cpp
File metadata and controls
65 lines (60 loc) · 1.13 KB
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
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using p = pair<int, int>;
const int INF = 0x66554433;
int arr[100][100];
inline void quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void construct(int a){
int num = 1;
if(a==3){
cout<<"2 9 7\n";
cout<<"4 6 3\n";
cout<<"1 8 5\n";
return;
}
for(int i = 0;i<a;i++){
for(int j = 0;j<a;j+=2){
arr[i][j] = num;
num++;
}
}
for(int i = 0;i<a;i++){
for(int j = 1;j<a;j+=2){
arr[i][j] = num;
num++;
}
}
for (int i = 0; i < a; ++i) {
for (int j = 0; j < a; ++j) {
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
quick_IO();
int t;
int i, j, k;
cin>>t;
while(t--){
int n;
cin>>n;
if(n==2){
cout<<-1<<'\n';
continue;
}
construct(n);
}
return 0;
}