#include <iostream>
#include <iomanip>
using namespace std;
int state = 1 ;
int Graph[100][100];
void chip_gram(int str , int stc , int enr , int enc , int t)
{
if (t == 1) return ;
int flag = state++;
t = t / 2;
if (str < enr+t && stc < enc+t)
chip_gram(str , stc , enr , enc , t);
else
{
Graph[ enr+t-1][enc+t-1] = flag;
chip_gram( enr+t-1 , enc+t-1 , enr , enc , t);
}
if (str >= enr+t && stc < enc+t)
chip_gram(str , stc , enr+t , enc , t);
else
{
Graph[ enr+t][enc+t-1] = flag;
chip_gram( enr+t , enc+t-1 , enr+t , enc , t);
}
if (str < enr+t && stc >= enc+t)
chip_gram(str , stc , enr , enc+t , t);
else
{
Graph[ enr+t-1][enc+t] = flag;
chip_gram( enr+t-1 , enc+t , enr , enc+t , t);
}
if (str >= enr+t && stc >= enc+t)
chip_gram(str , stc , enr+t , enc+t , t);
else
{
Graph[ enr+t][enc+t] = flag;
chip_gram( enr+t , enc+t , enr+t , enc+t , t);
}
}
int main ()
{
int size,m,n; //棋盘的大小;已知方格的位置;
cout<<"输入棋盘大小:"<<endl;
cin >> size ;
cout<<"输入已知方格的横纵坐标:"<<endl;
cin >> m >> n;
chip_gram(m,n,0,0,size);
for(int i = 0;i < size; i++)
{
for (int j = 0;j < size; j++)
cout<<setw(3)<<Graph[i][j];
cout<<endl;
}
return 0;
}