Title Link: https://vijos.org/p/1360
Main topic:
3x3 Lattice put 1~8 number, a vacancy, each vacancy can be exchanged with the upper and lower left and right, fixed terminate the layout, the initial layout of the input needs a few steps to reach the end of the layout
Topic Ideas:
One eye problem BFs, wide search can, sentence weight I compare violence directly put down the state, no hash, Cantor or anything.
1 //2 //by Coolxxx3 //4#include <iostream>5#include <algorithm>6#include <string>7#include <iomanip>8#include <memory.h>9#include <time.h>Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> -#include <stdbool.h> -#include <math.h> the #defineMin (a) < (b) ( A):(B)) - #defineMax (a) (a) > (b)? ( A):(B)) - #defineABS (a) ((a) >0? ( A):(-(a))) - #defineSqr (a) (a) * (a) + #defineSwap (a) (a) ^= (b), (b) ^= (a), (a) ^= (b) - #defineEPS 1e-8 + #defineS 10000 A #defineMAX 0x7f7f7f7f at #definePI 3.1415926535897 - #defineN 14 - #defineM 100000 - using namespacestd; - intN,m,cas,lll,ans; - intr[n]={1,Ten, -, +,10000,100000,1000000,10000000,100000000}; in intd[4]={-3,-1,1,3}; - intq[m][n]={1,2,3,8,0,4,7,6,5}; to intV[m]; + BOOLu[87654321]; - BOOLOkintXinty) the { * if(y==-3)return(x/3>0); $ if(y==-1)return(%3>0);Panax Notoginseng if(y==1)return(%3<2); - if(y==3)return(x/3<2); the } + intSPFA () A { the inti,j,now,h=-1, t=0; + intx; -u[m%r[8]]=1; $ while(h++<t) $ { - for(x=0, i=0;i<9; i++) - { thex+=q[h][i]*r[8-i]; - if(q[h][i]==0) now=i;Wuyi } the if(x==n)returnV[h]; - for(i=0;i<4; i++) Wu { - if(OK (Now,d[i])) About { $memcpy (q[t+1],Q[H],sizeof(Q[h])); -Swap (q[t+1][now],q[t+1][now+D[i]]); - for(x=0, j=1;j<9; j + +) -x+=q[t+1][j]*r[8-j]; A if(!U[x]) + { thev[++t]=v[h]+1; -u[x]=1; $ } the } the } the } the } - intMain () in { the #ifndef Online_judge the //freopen ("1.txt", "R", stdin); About //freopen ("2.txt", "w", stdout); the #endif the inti,j,k; the //while (~scanf ("%s%s", SN,SM)) + while(~SCANF ("%d", &n) &&N) - { them=123804765;Bayiprintf"%d\n", SPFA ()); the } the return 0; - } - the the /* the // the - // the */
View Code
Vijos P1360 Eight digital issues