#include
INT N, M; typef struct node {char matrix [10]; / * Storage matrix * / char Operate; / * Store cannot be performed, l Depending on the left shift R represents that cannot be right-shifted U. Can not move down * / char extend; / * Can be extended, Y representative, n representative can not * / int fit; / * Point to generate its own form * /} node; char start [10] = {"83426517 "}; / * There is no need to initialize * / char end [10] = {" 1238 4765 "}; / * There is no need to initialize * / node base [4000]; int result [100]; / * Storage results Base array sub-reference, reverse sequence storage * / int match () / * judgment is the target * / {INT i; for (i = 0; i <9; i ) {IF (Base [N-1] .Matrix [ I]! = end [i]) {return 0;}} Return 1;
Void show () / * Display matrix content * / {INT i = 1; while (m> = 0) {INT mm = result [m]; clrs CR (); printf ("/ n / n / n http: / / www.zhensoft.com Zhen Shi Lei / T / TSTEP% D ", I); Printf (" / N / N / N / N / N / T / T% C / T% C / T% C / n ", base [mm]. matrix [0], base [mm] .matrix [1], base [mm] .matrix [2]); printf (" / n / n / t / t / t% C / T% C / T% C / N ", Base [mm]. matrix [3], base [mm] .matrix [4], base [mm] .matrix [5]); printf (" / n / n / T / T% C / T% C / T% C / N ", Base [mm]. matrix [6], base [mm] .matrix [7], base [mm] .matrix [8]); Sleep (1); m -; i ;}}
Void Leave () / * After the reason is successful, the function to be executed before you exit the program, the main function is the output result * / {n -; while (base [n] .father! = - 1) {result [m] = n; M ; n = base [n] .father;} result [m] = 0; Result [m 1] = '/ 0'; show (); CLRSCR (); printf ("/ n / n / n / n / N / N / N / N / N / T / T / T / TTHE End / N / N / N / N / N / N / N / N / N / N "); getCh (); exit (0) }
INT LEFT (INT x) / * left the space of the matrix in the array of the subscript * / {INT I, J; CHAR CH; for (i = 0; I <9; i ) {IF (Base [ x]. matrix [i] == ') Break;} if (i == 0 || i == 3 || i == 6 || i == 9) {RETURN 0;}
For (j = 0; j <9; j ) {base [n] .matrix [j] = base [x] .matrix [j];} ch = base [n] .matrix [i-1]; base [ n]. matrix [i-1] = base [n] .matrix [i]; base [n]. matrix [i] = ch; base [n] .Operate = 'r'; base [n] .extend = 'Y'; base [n] .father = x; base [x] .extend = 'n'; n ; if (Match (i)) Leave (); return 1;}
INT RIGHT (INT X) / * Right shift to the matrix in the array of subscript x * / {INT I, J; Char CH; for (i = 0; i <9; i ) {ix (base [ x]. matrix [i] == ') Break;} if (i == 2 || i == 5 || i == 8 || i == 9) {return 0;}
For (j = 0; j <9; j ) {base [n] .matrix [j] = base [x] .matrix [j];} ch = base [n] .matrix [i 1]; base [ n]. matrix [i 1] = base [n]. matrix [i]; base [n]. matrix [i] = ch; base [n] .Operate = 'l'; base [n] .extend = 'Y'; base [n] .father = x;
Base [x] .extend = 'n'; n ; if (Match (i)) Leave (); return 1;}
INT UP (INT X) / * Split the space of the matrix in the array of the subscript x * / {INT I, J; Char CH; for (i = 0; I <9; i ) {IF (Base [ x] .matrix [i] == ') Break;} if (i == 0 || i == 1 || i == 2 || i == 9) {RETURN 0;}
For (j = 0; j <9; j ) {base [n] .matrix [j] = base [x] .matrix [j];} ch = base [n] .matrix [i-3]; base [ n]. matrix [i-3] = base [n] .matrix [i]; base [n]. matrix [i] = ch; base [n]. galed = 'd'; base [n] .extend = 'Y'; base [n] .father = x;
Base [x] .extend = 'n'; n ; if (Match (i)) Leave (); return 1;}
INT DOWN / * Split the space of the matrix in the array of the subscript * / {INT I, J; CHAR CH; For (i = 0; I <9; i ) {ix (base [ x]. matrix [i] == ') Break;} IF (i == 6 || i == 7 || i == 8 || i == 9) {RETURN 0;}
For (j = 0; j <9; j ) {base [n] .matrix [j] = base [x] .matrix [j];} ch = base [n] .matrix [i 3]; base [ n]. matrix [i 3] = base [n]. matrix [i]; base [n]. matrix [i] = ch; base [n] .Operate = 'u'; base [n] .extend = 'Y'; base [n] .father = x; base [x] .extend = 'n'; n ; if (Match (i)) Leave (); return 1;}
Main () {Int i; char a [20], b [20]; n = 1;
TEXTCOLOR (LightGreen); CLRSCR ();
/ * The following is the input initial and target matrix, convert the input 0 to space * / printf ("Please Input The Start 9 Chars:"); Scanf ("% S", A); Printf ("please input the end 9 Chars: "); scanf ("% s ", b); for (i = 0; i <9; i ) {if (a [i] == '0') {start [i] = ''; Continue;} if (b [i] == '0') {end [i] = ''; Continue;} start [i] = a [i]; end [i] = b [i];} start [ 9] = '/ 0'; END [9] = '/ 0';
For (i = 0; i <9; i ) {base [0] .matrix [i] = start [i];} base [0] .Operate = 'n'; base [0] .extend = 'y' Base [0] .father = -1; / * The above is assigned to the first base array element * / for (i = 0; n <4000; i ) {if (base [i] .extend == 'y ') {If (base [i] .Operate ==' L ') {Right (i); Up (i); DOWN (i);} if (base [i] .Operate ==' r ') {Left (i); Up (i); Down (i);} if (base [i] .Operate == 'u') {left (i); Right (i); DOWN (I);} if (base [ I]. ga == 'd') {Left (i); Right (i); Up (i);} if (base [i] .Operate == 'n') {left (i); Right (i ); UP (i); Down (i);}}}}}