提交时间:2024-08-21 15:45:52
运行 ID: 180535
#include<bits/stdc++.h> using namespace std; int n,flag=0,a[20][20],dx[8]={-2,-2,-1,1,2,3,1,-1},dy[8]={-1,1,2,2,1,-1,-2,-2}; void dfs(int x,int y,int num){ int x1,y1; if(num==n*n){ flag=1; return 0; } for(int i=0;i<8;i++){ x1=x+dx[i]; y1=y+dy[i]; if(x1>0&&x1<=n&&y1>0&&y1<=n&&!a[x1][y1]){ num++; a[x1][y1]=num; dfs(x1,y1,num); num--; if(flag)return; a[x1][y1]=0; } x1=x-dx[i]; y1=y-dy[i]; } } int main(){ int x,y,a[100000],n; cin>>n>>x>>y; a[x][y]=1; dfe(x,y,1); for(int i=0;;i++){ } return 0; }