pos*nx!=6有什么用?
#include<bits/stdc++.h>
using namespace std;
string ss;
string t="123804765";
int d[4]={-1,1,-3,3};
struct str{
string s;
int step;
};
map<string,int>used;
int bfs(){
queue<str>q;
q.push({ss,0});
used[ss]=1;
while(!q.empty()){
str f=q.front();
q.pop();
if(f.s==t)return f.step;
int pos=f.s.find("0",0);
for(int i=0;i<4;i++){
int nx=pos+d[i];
if(nx>=0&&nx<9&&pos*nx!=6&&pos*nx!=30){
string tmp=f.s;
swap(tmp[pos],tmp[nx]);
if(!used[tmp]){
q.push({tmp,f.step+1});
used[tmp]=1;
}
}
}
}
}
int main(){
cin>>ss;
cout<<bfs();
return 0;
}