八码数 · 哈希+BFS
//本代码还未ac # include <bits/stdc++.h> using namespace std ; typedef long long ll ; # define between(x, a, b) (a<=x && x<=b) const int dir [ 4 ] [ 2 ] = { 1 , 0 , 0 , 1 , - 1 , 0 , 0 , - 1 } ; const int N = 1e6 + 10 ; int n , m , K ; int f [ 15 ] , vis [ N ] ; struct node { string s = "" ; int pos ; //x的位置 int step ; } ; int id ( string s ) { //一种哈希方式 变排列 int res = 0 ; for ( int i = 0 ; i < 9 ; ++ i ) { int d = 0 ; for ( int j = 0 ; j < i ; ++ j ) { if ( s [ j ] > s [ i ] ) d ++ ; } res + = d * f [ i ] ; } return res ; } int dfs ( node st ) { vis [ id ( st . s ) ] = 1 ; queue < node > q ; q .