//棋盘覆盖
#include<iostream>
#include<cmath>
using namespace std;
int tile;
int k;
int board[100][100];
void printChessBoard(int s)
{
for(int i=0;i<s;i++)
{
for(int j=0;j<s;j++)
cout<<board[i][j];
cout<<endl;
}
}
void chessBoard(int tx,int ty,int dx,int dy,int size)
{
if(size==1) return;
int t=tile++;
int s=size/2;
if(dx<tx+s&&dy<ty+s)//left-top
{
chessBoard(tx,ty,dx,dy,s);
}
else
{
board[tx+s-1][ty+s-1]=t;
chessBoard(tx,ty,tx+s-1,ty+s-1,s);
}
if(dx>=tx+s&&dy<ty+s)//right-top
{
chessBoard(tx+s,ty,dx,dy,s);
}
else
{
board[tx+s][ty+s-1]=t;
chessBoard(tx+s,ty,tx+s,ty+s-1,s);
}
if(dx<tx+s&&dy>=ty+s)//left-bottom
{
chessBoard(tx,ty+s,dx,dy,s);
}
else
{
board[tx+s-1][ty+s]=t;
chessBoard(tx,ty+s,tx+s-1,ty+s,s);
}
if(dx>=tx+s&&dy>=ty+s)//right-bottom
{
chessBoard(tx+s,ty+s,dx,dy,s);
}
else
{
board[tx+s][ty+s]=t;
chessBoard(tx+s,ty+s,tx+s,ty+s,s);
}
}
int main()
{
int x,y;
while(cin>>k>>x>>y)
{
tile=0;
memset(board,0,sizeof(board));
chessBoard(0,0,x,y,k);
printChessBoard(k);
}
return 0;
}
棋盘覆盖
最新推荐文章于 2024-05-28 12:14:19 发布