提交时间:2024-08-21 16:03:42
运行 ID: 180561
#include<bits/stdc++.h> using namespace std; int n; int a[11][11]; int xd[8]={-2,-2,-1,1,2,2,1,-1}; int yd[8]={-1,1,2,2,1,-1,-2,-2}; int q=0; void f(int x,int y,int m){ if(m==n*n){ q=1; return; } for(int i=0;i<8;i++){ int x1=x+xd[i]; int y1=y+yd[i]; if(x1>0&&x1<=n&&y1>0&&y1<=n&&!a[x1][y1]){ m++; a[x1][y1]=m; f(x1,y1,m); m--; if(q)return; a[x1][y1]=0; } } } int main(){ int x,y,i,j; cin>>n>>x>>y; a[x][y]=1; f(x,y,1); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ cout<<a[i][j]<<" "; } cout<<endl; } }