<Span style = "color: #330099;">/* C-wide search Basic time limit: 1000 ms memory limit: 65536kb 64bit Io format: % i64d & % i64usubmit statusdescriptiona friend of you is doing research on the traveling knight problem (tkp) where you are to find the shortest closed tour of knight moves that visits each square of a given set of N squares on a chessboard exactly once. he thinks that the most difficult part of the problem is determining the smallest number of knight moves between two given squares and that, once you have accomplished this, finding the tour wocould be easy. of course you know that it is vice versa. so you offer him to write a program that solves the "difficult" part. your job is to write a program that takes two squares A and B as input and then determines the number of knight moves on a shortest route from A to B. inputthe input will contain in one or more test cases. each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a-h) representing the column and a digit (1-8) representing the row on the chessboard. outputfor each test case, print one line saying "to get from xx to YY takes n knight moves. ". sample inpute2 e4a1 b2b2 c3a1 h8a1 rjh8 a1b1 c3f6 f6sample outputto get from E2 to E4 takes 2 knight moves. to get from A1 to B2 takes 4 knight moves. to get from B2 to C3 takes 2 knight moves. to get from A1 to H8 takes 6 knight moves. to get from A1 to H7 takes 5 knight moves. to get from H8 to A1 takes 6 knight moves. to get from B1 to C3 takes 1 knight moves. to get From F6 to F6 takes 0 knight moves. by grant yuan2014.7.12 */# include <iostream> # include <stdio. h> # include <string. h >#include <queue >#include <cstdio> using namespace STD; bool flag [21] [21]; char a [21] [21]; int n, m; int S1, F1; typedef struct {int X; int y;} node; int next [4] [2] = {,-, 0,-1 }; int sum; node Q [10000]; int top, base; bool can (int cc, int dd) {If (CC> = 0 & CC <M & DD> = 0 & DD <n & flag [CC] [DD] = 0) return 1; return 0;} void slove () {int C, D, CC, DD; node Q1; while (top> = base) {// C = Q. front (). x; D = Q. front (). y; C = Q [base]. x; D = Q [base]. y; For (INT I = 0; I <4; I ++) {cc = C + next [I] [0]; dd = d + next [I] [1]; If (CAN (CC, DD) {q1.x = cc; q1.y = dd; // cout <CC <"<DD <Endl; // Q. push (Q1); Q [++ top] = Q1; flag [CC] [DD] = 1; sum ++ ;}// Q. pop (); base ++ ;}} int main () {node Q1; while (1) {sum = 1; Top =-1; base = 0; memset (flag, 0, sizeof (FLAG); CIN> N> m; If (n = 0 & M = 0) break; For (INT I = 0; I <m; I ++) {// cout <"Zhang" <Endl; scanf ("% s", & A [I]);} // For (INT I = 0; I <m; I ++) // puts (A [I]);/* For (INT I = 0; I <m; I ++) puts (A [I]); */For (INT I = 0; I <m; I ++) for (Int J = 0; j <N; j ++) {if (a [I] [J] = '#') Flag [I] [J] = 1; if (A [I] [J] = '@') S1 = I, F1 = J;} q1.x = S1; q1.y = F1; flag [S1] [F1] = 1; // For (INT I = 0; I <m; I ++) // For (Int J = 0; j <N; j ++) {// cout <flag [I] [J]; // If (j = N-1) cout <Endl ;}// Q. push (Q1); Q [++ top] = Q1; slove (); cout <sum <Endl ;}return 0 ;}</span>