P760通天之汉诺塔

https://www.luogu.com.cn/problem/P1760

用递归计算移动容易超时,
借助公式 2^n - 1
当数据太大时,公式无效,算不出大数
例如:

#include <bits/stdc++.h>
using namespace std;
int n;
stringstream b;
string c;
int main(){
    //freopen("out","w",stdout);
    cin >> n;
    b.precision(0);
    b << fixed << pow(2.0L,n);
    c = b.str();
    c[c.length() - 1]--;
    cout << c;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/xcfxcf/p/12583215.html
今日推荐