如何创建网站后台,官网和门户网站的区别,云南网站设计多少钱,西宁做网站君博解决solution
有一个测试点没有空格#xff0c;要特别处理#xff0c;否则会有一个测试点运行错误#xff01; 还有输入数据的规模在变#xff0c;小心顺手敲错了边界条件
#includeiostream
#includestring
#includequeue
#includemap
#incl…
solution
有一个测试点没有空格要特别处理否则会有一个测试点运行错误 还有输入数据的规模在变小心顺手敲错了边界条件
#includeiostream
#includestring
#includequeue
#includemap
#includealgorithm
using namespace std;
string start, t;
mapstring, int mp;
int ax, ay, x, y, d, k;
int X[4] {-1, 1, 0, 0};
int Y[4] {0, 0, -1, 1};int bfs(string s){queuestring q;q.push(s);while(!q.empty()){t q.front();q.pop();if(t.find(A) ay t.find(B) ax) return mp[t];k t.find( );for(int i 0; i 4; i){x k / 3 X[i];y k % 3 Y[i];if(x 0 || x 2 || y 0 || y 3) continue;d mp[t];swap(t[k], t[3 * x y]);if(!mp.count(t)){mp[t] d 1;q.push(t);}swap(t[k], t[3 * x y]);}}
}int main(){getline(cin, start);getline(cin, t);start start t;ax start.find(A);ay start.find(B);if(start.find( ) start.npos) cout 10;else cout bfs(start);return 0;
}