class Knight{ 
private: 
     int dirx[8];//八个方向可以走,用两个数组分别记录每个方向上x,y的坐标位移 
     int diry[8]; 
public: 
     Knight()
  { 
            dirx[0]=1;diry[0]=2; 
            dirx[1]=2;diry[1]=1; 
            dirx[2]=1;diry[2]=-2; 
            dirx[3]=2;diry[3]=-1; 
            dirx[4]=-1;diry[4]=2; 
            dirx[5]=-2;diry[5]=1; 
            dirx[6]=-1;diry[6]=-2; 
            dirx[7]=-2;diry[7]=-1; 
} 
private: 
      bool judge(int y,int x){ 
      if(x>0 && x<=n && y>0 && y<=n && map[y][x]==0) 
          return true; 
      else 
          return false; 
} 
public: 
      void set(int y,int x,int t){ 
      if(t==n*n)
   { 
             map[y][x]=t; 
             cout<<"one possible answer:"<<endl; 
             for(int i=1;i<=n;i++){ 
             for(int j=1;j<=n;j++){ 
原文请找腾讯752018766辣,文-论'文.网http://www.751com.cn/    } 
else
{ 
      if(map[y][x]==0){ 
      map[y][x]=t; 
      int nextt=t+1; 
      for(int i=0;i<8;i++)
   { 
        if(judge(y+diry[i],x+dirx[i])) 
        set(y+diry[i],x+dirx[i],nextt); 
   } 
   map[y][x]=0; 
   } 
} 
   } 
}; 
void main()
{ 
    Knight *horse=new Knight();//骑士也要走马步 
    for(int i=1;i<=8;i++) 
    for(int j=1;j<=8;j++) 
    map[i][j]=0; 
    for(i=1;i<=n;i++) 
    for(int j=1;j<=n;j++) 
    horse->set(i,j,1); 
    delete horse;