注意输出格式和换行,注意不要用文件输入输出,这里不用文件!
by ILovePhysics @ 2019-11-08 08:03:56
@[ILovePhysics](/user/221900) 都注意了,在其他oj上交就挂了,和题解对拍也拍不出来...
by 猪小屁 @ 2019-11-08 09:17:09
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string,bool>mp;
struct mb{
string a[3],han;
int step;
friend bool operator <(mb x,mb y){
if(x.step==y.step) return (x.han)>(y.han);
return x.step>y.step;
}
}m;
void bfs(mb bb){
priority_queue<mb>q;
q.push(bb);
string llw;
llw=bb.a[1]+bb.a[2];
mp[llw]=1;
while(!q.empty()){
mb now=q.top();
q.pop();
if(now.a[1]==m.a[1]&&now.a[2]==m.a[2]){
printf("%d\n",now.step);
int siz=now.han.size();
if(siz<=60){
cout<<now.han<<endl;
}
else{
for(int i=1;i<=siz/60;i++){
for(int j=0+(i-1)*60;j<=59+(i-1)*60;j++){
cout<<now.han[j];
}
printf("\n");
}
for(int i=(siz/60)*60;i<siz;i++){
cout<<now.han[i];
}
printf("\n");
}
return;
}
for(int i=1;i<=3;i++){
mb cs=now;
if(i==1){
cs.han=cs.han+"A";
// cout<<cs.han<<endl;
cs.step++;
string tmp=cs.a[1];
cs.a[1]=cs.a[2];
cs.a[2]=tmp;
// cout<<cs.a[1]<<cs.a[2]<<endl;
string pyf;
pyf=cs.a[1]+cs.a[2];
if(mp[pyf]) continue;
mp[pyf]=1;
q.push(cs);
}
if(i==2){
cs.han=cs.han+"B";
// cout<<cs.han<<endl;
cs.step++;
string tmp=cs.a[1];
cs.a[1].erase(3,1);
cs.a[1].insert(0,tmp.substr(3,1));
tmp=cs.a[2];
cs.a[2].erase(3,1);
cs.a[2].insert(0,tmp.substr(3,1));
// cout<<cs.a[1]<<cs.a[2]<<endl;
string pyf=cs.a[1]+cs.a[2];
if(mp[pyf]) continue;
mp[pyf]=1;
q.push(cs);
}
if(i==3){
cs.han=cs.han+"C";
// cout<<cs.han<<endl;
cs.step++;
string tmp1,tmp2;
tmp1=cs.a[1];
tmp2=cs.a[2];
cs.a[1].replace(1,1,tmp2.substr(1,1));
cs.a[1].replace(2,1,tmp1.substr(1,1));
cs.a[2].replace(1,1,tmp2.substr(2,1));
cs.a[2].replace(2,1,tmp1.substr(2,1));
string pyf=cs.a[1]+cs.a[2];
if(mp[pyf]) continue;
mp[pyf]=1;
q.push(cs);
}
}
}
}
int main(){
// freopen("a.in","r",stdin);
// freopen("biao.out","w",stdout);
mb fir;
fir.a[1]="1234";
fir.a[2]="8765";
string cc;
getline(cin,cc);
int siz=cc.size();
for(int i=0;i<siz;++i){
if(cc[i]>'8'||cc[i]<'0'){
cc.erase(i,1);
siz--;
i--;
}
}
char xx[4];
xx[0]=cc[7];
xx[1]=cc[6];
xx[2]=cc[5];
xx[3]=cc[4];
m.a[1]=cc.substr(0,4);
m.a[2]=m.a[2]+xx;
// cout<<m.a[1]<<m.a[2]<<endl;
fir.step=0;
bfs(fir);
return 0;
}
/*
2 6 8 4 5 7 3 1
*/
```
by 猪小屁 @ 2019-11-08 09:17:51
@[ILovePhysics](/user/221900) 发错了,是在其他oj上过了
by 猪小屁 @ 2019-11-08 09:18:25