構造。
先只考慮用$0$和$1$構造矩陣。
$n=1$,$\left[ 1 \right]$。
$n=3$,(在$n=1$的基礎上,最外一圈依次標上$0$,$1$,$0$,$1$......)
$\left[ {\begin{array}{*{20}{c}}
0&1&0\\
1&1&1\\
0&1&0
\end{array}} \right]$。
$n=5$,(在$n=3$的基礎上,最外一圈依次標上$1$,$0$,$1$,$0$......)
$\left[ {\begin{array}{*{20}{c}}
1&0&1&0&1\\
0&0&1&0&0\\
1&1&1&1&1\\
0&0&1&0&0\\
1&0&1&0&1
\end{array}} \right]$。
輸出的時候我們再將$1$至${n^2}$這些數替換$0$和$1$。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} int a[][],n,st; void work(int r1,int c1,int r2,int c2,int f)
{
for(int j=c1;j<=c2;j++) a[r2][j]=a[r1][j]=f, f=f^;
f=f^;for(int i=r1;i<=r2;i++) a[i][c2]=a[i][c1]=f,f=f^;
} int main()
{
scanf("%d",&n);
if(n%==) st=; else st=;
int x1=,y1=,x2=n,y2=n;
while()
{
work(x1,y1,x2,y2,st);
if(x1==x2&&y1==y2) break;
x1++; y1++; x2--; y2--; st=st^;
} int k1=,k2=;
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(a[i][j]%==) a[i][j]=k1, k1=k1+;
else a[i][j]=k2, k2=k2+;
}
} for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return ;
}