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
|
#include<bits/stdc++.h> using namespace std; const int maxn=1e4+10; int m[maxn][maxn]; int n=0; void chessboard(int x,int y,int tx,int ty,int s){ if(s==1) return; s>>=1; int t=++n; if(tx<=x+s-1&&ty<=y+s-1) chessboard(x,y,tx,ty,s); else m[x+s-1][y+s-1]=t,chessboard(x,y,x+s-1,y+s-1,s); if(tx<=x+s-1&&ty>=y+s) chessboard(x,y+s,tx,ty,s); else m[x+s-1][y+s]=t,chessboard(x,y+s,x+s-1,y+s,s); if(tx>=x+s&&ty<=y+s-1) chessboard(x+s,y,tx,ty,s); else m[x+s][y+s-1]=t,chessboard(x+s,y,x+s,y+s-1,s); if(tx>=x+s&&ty>=y+s) chessboard(x+s,y+s,tx,ty,s); else m[x+s][y+s]=t,chessboard(x+s,y+s,x+s,y+s,s); } int main(){ while(true){ int size; cin>>size; int x,y; cin>>x>>y; chessboard(1,1,x,y,size); for(int i=1;i<=size;i++){ for(int j=1;j<=size;j++){ printf("%3d ",m[i][j]); } printf("n"); } } }
|
近期评论