3 条题解

  • 1
    @ 2023-6-24 19:04:19
    #include <bits/stdc++.h>
    using namespace std;
    int n, f[20];
    int main()
    {
        cin >> n;
        f[1] = 1;
        for (int i = 2; i <= n; i++)
        {
            f[i] = 2 * f[i - 1] + 1;
        }
        cout << f[n];
        return 0;
    }
    
  • 0
    @ 2023-7-14 19:45:01

    另一个公式:f个移动2*(f-1个移动次数)+1

    #include <bits/stdc++.h>
    using namespace std;
    int times(int x){
        if(x==1){
            return x;
        }else{
            return times(x-1)*2+1;
        }
    }
    int main(){
        int n;
        cin>>n;
        cout<<times(n)<<endl;
        return 0;
    }
    
    • 0
      @ 2023-7-14 19:41:00

      公式:f个移动2^f-1次

      #include <bits/stdc++.h>
      using namespace std;
      int main(){
          int n;
          cin>>n;
          cout<<pow(2,n)-1<<endl;
          return 0;
      }
      
      • 1

      【入门】汉诺塔的移动次数

      信息

      ID
      223
      时间
      1000ms
      内存
      128MiB
      难度
      2
      标签
      递交数
      77
      已通过
      50
      上传者