1 条题解

  • 1
    @ 2024-7-30 17:45:06
    #include<bits/stdc++.h>
    using namespace std;
    vector<int> dfs(int n) {
    vector<int> ovo;
    while (n != 1) {
    ovo.push_back(n);
    if (n % 2 == 0) {
    n /= 2;
    }
    else {
    n = 3 * n + 1;
    }
    }
    ovo.push_back(1);
    return ovo;
    }
    int main() {
    int n;
    cin >> n;
    vector<int> ovo = dfs(n);
    for (auto it = ovo.rbegin(); it != ovo.rend(); ++it) {
    cout << *it << " ";
    }
    cout << endl;
    return 0;
    }
    

    信息

    ID
    702
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    (无)
    递交数
    55
    已通过
    21
    上传者