跳至正文

1 条题解

  • 0
    @ 2026-10-2 2:21:53

    动态字符串记录棋盘并递归生成合法过程,覆盖n=1000。

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){ios::sync_with_stdio(false);cin.tie(nullptr);
    
    int n;cin>>n;string a=string(n,'o')+string(n,'*')+"--";int gap=2*n,step=0;auto print=[&](){cout<<"step"<<setw(2)<<step++<<":"<<a<<"\n";};auto move=[&](int source){source--;a[gap]=a[source];a[gap+1]=a[source+1];a[source]=a[source+1]='-';gap=source;print();};function<void(int)>solve=[&](int m){if(m==4){for(int x:{4,8,2,7,1})move(x);}else{move(m);move(2*m-1);solve(m-1);}};print();solve(n);
    
    return 0;
    }
    
    • 1

    信息

    ID
    4002
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    0
    已通过
    0
    上传者