122121
zqrmon
·
·
个人记录
#include <bits/stdc++.h>
using namespace std;
int main() {
string ed;
char c[8];
bool b=0;
for (int i = 0; i < 8; ++i) {
cin >> c[i];
if(c[i]!=i+1+'0'){
b=1;
}
ed += c[i];
}
if(b==0){
cout<<0;
}
queue<string> q;
map<string, string> mp;
q.push("12345678");
mp["12345678"] = "";
while (!q.empty()) {
string s = q.front(); q.pop();
{
string x = s;
for (int i = 0; i < 4; ++i)
swap(x[i], x[7 - i]);
if (mp.count(x) == 0) {
mp[x] = mp[s] + 'A';
q.push(x);
if (x == ed) {
cout << mp[x].size() << endl << mp[x];
return 0;
}
}
}
{
string x = s;
x[0] = s[3]; x[1] = s[0]; x[2] = s[1]; x[3] = s[2];
x[4] = s[5]; x[5] = s[6]; x[6] = s[7]; x[7] = s[4];
if (mp.count(x) == 0) {
mp[x] = mp[s] + 'B';
q.push(x);
if (x == ed) {
cout << mp[x].size() << endl << mp[x];
return 0;
}
}
}
{
string x = s;
x[1] = s[6]; x[2] = s[1]; x[5] = s[2]; x[6] = s[5];
if (mp.count(x) == 0) {
mp[x] = mp[s] + 'C';
q.push(x);
if (x == ed) {
cout << mp[x].size() << endl << mp[x];
return 0;
}
}
}
}
return 0;
}