#include<stdio.h>
int title;
int board[20][20];
void chessboard(int tr,int tc,int r,int c,int size)
{
int s,t;
if(size==1)
{
return ;
}
s=size/2;
t=++title;
if(tr<r+s&&tc<c+s)
{
chessboard(tr,tc,r,c,s);
}
else
{
board[r+s-1][c+s-1]=t;
chessboard(r+s-1,c+s-1,r,c,s);
}
if(tr<r+s&&tc>=c+s)
{
chessboard(tr,tc,r,c+s,s);
}
else
{
board[r+s-1][c+s]=t;
chessboard(r+s-1,c+s,r,c+s,s);
}
if(tr>=r+s&&tc<c+s)
{
chessboard(tr,tc,r+s,c,s);
}
else
{
board[r+s][c+s-1]=t;
chessboard(r+s,c+s-1,r+s,c,s);
}
if(tr>=r+s&&tc>=c+s)
{
chessboard(tr,tc,r+s,c+s,s);
}
else
{
board[r+s][c+s]=t;
chessboard(r+s,c+s,r+s,c+s,s);
}
}
int main()
{
int tr,tc,size,i,j;
while(scanf("%d%d%d",&size,&tr,&tc)!=EOF)
{
chessboard(tr,tc,0,0,size);
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
printf("%d ",board[i][j]);
}
printf("\n");
}
}
return 0;
}
棋盘覆盖
最新推荐文章于 2024-04-27 23:19:08 发布