1 #include <iostream>
2 using namespace std;
3 struct chess{
4 int x;
5 int y;
6 int step;
7 int prep;
8 };
9 chess point[26];
10 int Dx[8]={-2,-1,1,2,2,1,-1,-2};
11 int Dy[8]={1,2,2,1,-1,-2,-2,-1};
12 int front=0;
13 int rear=0;
14 int map[5][5]={0};
15 int ax;
16 int ay;
17 int schess(int x,int y);
18
19
20 int main()
21 {
22 int x;
23 int y;
24 int n=0;
25 int step;
26 cin >>x;
27 cin >>y;
28 ax=1;
29 ay=1;
30 step=schess(x,y)-1;
31
32 cout <<step<<endl;
33 n=point[rear-1].prep;
34 while(n!=0)
35 {
36 cout <<"("<<point[n].x<<","<<point[n].y<<") ";
37 n=point[n].prep;
38 }
39 cout <<"("<<point[n].x<<","<<point[n].y<<")";
40
41 return 0;
42 }
43
44 int schess(int x,int y)
45 {
46 int mx;
47 int my;
48 int a=0;
49 point[rear].x=x;
50 point[rear].y=y;
51 point[rear++].step=1;
52 map[x][y]=point[0].step;
53 while(rear>front)
54 {
55 for(int i=0;i<8;i++)
56 {
57 mx=point[front].x+Dx[i];
58 my=point[front].y+Dy[i];
59
60 if(mx>=0&&my>=0&&mx<5&&my<5&&map[mx][my]==0)
61 {
62 point[rear].x=mx;
63 point[rear].y=my;
64 point[rear].prep=front;
65 point[rear++].step=point[front].step+1;
66 map[mx][my]=point[rear].step;
67 if(mx==ax&&my==ay)
68 {
69 a=1;
70 break;
71 }
72 }
73 }
74 if(a==1)
75 break;
76 front++;
77 }
78 return point[rear-1].step;
79 }