题目链接:https://blog.csdn.net/wly_2014/article/details/51388263
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=64; 4 int n, matchlist[maxn+1][maxn+1]; 5 6 void makelist(int a1, int b1, int a2, int b2, int x, int y){ 7 if(x==y)matchlist[a1][b1]=x; 8 else{ 9 int a3=(a1+a2)/2, b3=(b1+b2)/2, xy=(x+y)/2; 10 makelist(a1, b1, a3, b3, x, xy); 11 makelist(a1, b3+1, a3, b2, xy+1, y); 12 makelist(a3+1, b1, a2, b3, xy+1, y); 13 makelist(a3+1, b3+1, a2, b2, x, xy); 14 } 15 } 16 void printlist(int n) 17 { 18 for(int i=1; i<=n; i++){ 19 for(int j=1; j<=n; j++) 20 cout<<setw(4)<<matchlist[i][j]; 21 cout<<endl; 22 } 23 } 24 int main() 25 { 26 cin>>n; 27 makelist(1, 1, n, n, 1, n); 28 printlist(n); 29 30 return 0; 31 }