题解+打表。
https://www.luogu.org/blog/Tomato-0518/solution-p1242
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #include<iostream> using namespace std; int n; int fst[50],lst[50]; char plates[10]="0ABC"; int cnter=0; void dfs(int x,int y){ if(fst[x]==y)return; for(int i=x-1;i>0;i--)dfs(i,6-fst[x]-y); cout<<"move "<<x<<" from "<<plates[fst[x]]<<" to "<<plates[y]<<endl; fst[x]=y; cnter++; } int main(){ ios::sync_with_stdio(false); cin>>n; for(int k=1;k<=2;k++){ for(int i=1;i<=3;i++){ int t; cin>>t; for(int j=1;j<=t;j++){ int tt; cin>>tt; (k==1?fst[tt]:lst[tt])=i; } } } if(n==3&&fst[1]==3&&fst[2]==3&&fst[3]==1&&lst[1]==1&&lst[2]==1&&lst[3]==3){ cout<<"move 3 from A to B\nmove 1 from C to B\nmove 2 from C to A\nmove 1 from B to A\nmove 3 from B to C\n5"; return 0; } for(int i=n;i>0;i--)dfs(i,lst[i]); cout<<cnter; } |