#include<iostream>
#include<memory>
using namespace std;
int size=8;
int board[8][8];
int tile=0;
void chessboard(int tr,int tc,int dr,int dc,int size)
{
if(size==1) return ;
int t=++tile,s=size/2;
if(dr<tr+s && dc<tc+s) //left_top
chessboard(tr,tc,dr,dc,s);
else{
board[tr+s-1][tc+s-1]=t;
chessboard(tr,tc,tr+s-1,tc+s-1,s);
}
if(dr<tr+s && dc>=tc+s) //right_top
chessboard(tr,tc+s,dr,dc,s);
else{
board[tr+s-1][tc+s]=t;
chessboard(tr,tc+s,tr+s-1,tc+s,s);
}
if(dr>=tr+s && dc>=tc+s) //right_down
chessboard(tr+s,tc+s,dr,dc,s);
else{
board[tr+s][tc+s]=t;
chessboard(tr+s,tc+s,tr+s,tc+s,s);
}
if(dr>=tr+s && dc<tc+s) //left_down
chessboard(tr+s,tc,dr,dc,s);
else{
board[tr+s][tc+s-1]=t;
chessboard(tr+s,tc,tr+s,tc+s-1,s);
}
}
int main()
{
int dr,dc;
memset(board,0,sizeof(board));
cout<<"棋盘为:"<<size<<"行列"<<"请输入特殊点的坐标:"<<endl;
cout<<"dr:";cin>>dr;
cout<<"dc:";cin>>dc;
if(dr>size-1|| dc>size-1){cout<<"输入错误"; exit(0);}
chessboard(0,0,dr,dc,size);
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
cout<<board[i][j]<<"\t";
cout<<endl;
}
cin.ignore();
getchar();
return 0;
}
#include<memory>
using namespace std;
int size=8;
int board[8][8];
int tile=0;
void chessboard(int tr,int tc,int dr,int dc,int size)
{
if(size==1) return ;
int t=++tile,s=size/2;
if(dr<tr+s && dc<tc+s) //left_top
chessboard(tr,tc,dr,dc,s);
else{
board[tr+s-1][tc+s-1]=t;
chessboard(tr,tc,tr+s-1,tc+s-1,s);
}
if(dr<tr+s && dc>=tc+s) //right_top
chessboard(tr,tc+s,dr,dc,s);
else{
board[tr+s-1][tc+s]=t;
chessboard(tr,tc+s,tr+s-1,tc+s,s);
}
if(dr>=tr+s && dc>=tc+s) //right_down
chessboard(tr+s,tc+s,dr,dc,s);
else{
board[tr+s][tc+s]=t;
chessboard(tr+s,tc+s,tr+s,tc+s,s);
}
if(dr>=tr+s && dc<tc+s) //left_down
chessboard(tr+s,tc,dr,dc,s);
else{
board[tr+s][tc+s-1]=t;
chessboard(tr+s,tc,tr+s,tc+s-1,s);
}
}
int main()
{
int dr,dc;
memset(board,0,sizeof(board));
cout<<"棋盘为:"<<size<<"行列"<<"请输入特殊点的坐标:"<<endl;
cout<<"dr:";cin>>dr;
cout<<"dc:";cin>>dc;
if(dr>size-1|| dc>size-1){cout<<"输入错误"; exit(0);}
chessboard(0,0,dr,dc,size);
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
cout<<board[i][j]<<"\t";
cout<<endl;
}
cin.ignore();
getchar();
return 0;
}