44 lines
851 B
C++
44 lines
851 B
C++
|
//AC
|
||
|
#include <iostream>
|
||
|
using namespace std;
|
||
|
|
||
|
const int MAX_N=39+5;
|
||
|
|
||
|
int main(){
|
||
|
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
|
||
|
|
||
|
int n;
|
||
|
cin>>n;
|
||
|
n=n/2*2+1;
|
||
|
int a[MAX_N][MAX_N];
|
||
|
for(int i=0;i<MAX_N;i++){
|
||
|
for(int j=0;j<MAX_N;j++){
|
||
|
a[i][j]=0;
|
||
|
}
|
||
|
}
|
||
|
const int pow_n = n*n;
|
||
|
int x=1,y=n/2+1;
|
||
|
a[x][y]=1;
|
||
|
for(int i=2;i<=pow_n;i++){
|
||
|
if(x==1&&y!=n){
|
||
|
x=n,y+=1;
|
||
|
}else if(y==n&&x!=1){
|
||
|
x-=1,y=1;
|
||
|
}else if(x==1&&y==n){
|
||
|
x+=1;
|
||
|
}else if(x!=1&&y!=n){
|
||
|
if(a[x-1][y+1]==0){
|
||
|
x-=1,y+=1;
|
||
|
}else{
|
||
|
x+=1;
|
||
|
}
|
||
|
}
|
||
|
a[x][y]=i;
|
||
|
}
|
||
|
for(int i=1;i<=n;i++){
|
||
|
for(int j=1;j<=n;j++){
|
||
|
cout<<a[i][j]<<" ";
|
||
|
}
|
||
|
cout<<endl;
|
||
|
}
|
||
|
}
|