#include <bits/stdc++.h> using namespace std; struct P{ int x; int y; int s; };

int mxy[12][2]={{1,2},{-1,2},{1,-2},{-1,-2},{2,1},{-2,1},{2,-1},{-2,-1},{2,2},{-2,2},{2,-2},{-2,-2}};

int bfs(){ bool b[20][20]={}; queue

q; int x,y; cin>>x>>y; P n={x,y,0}; q.push(n); while(!q.empty()){ P now=q.front(); cout<<now.x<<"---"<<now.y<<endl; for(int i=0;i<12;i++){ int xx=mxy[i][0]+now.x; int yy=mxy[i][1]+now.y;

	    if(b[xx][yy]==0 && xx<21 && yy<21 && xx>=0 && yy>=0){
			cout<<xx<<' '<<yy<<endl;
	    	b[xx][yy]=1;
	    	P next={xx,yy,now.s+1};
	    	if(xx==1&&yy==1){
	    		return now.s;
			}
	    	q.push(next);
		}	
	}
	q.pop();
}

} int main(){ cout<<bfs()<<endl; // for(int i=0;i<20;i++){ // for(int j=0;j<20;j++){ // b[i][j]=0; // } // } //cout<<bfs(); return 0; }

1 条评论

  • 1