求大佬指导高精

P1255 数楼梯

cycycy0530 @ 2024-07-12 13:39:28

#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[5005];
signed main(){
    int n;
    cin>>n;
    a[1]=1;a[2]=2;
    for(int i=3;i<=n;i++)
    a[i]=a[i-1]+a[i-2];
    cout<<a[n]<<endl;
    return 0;
}

by King_and_Grey @ 2024-07-12 13:51:25

@cycycy0530

#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
struct Bigint {
    int len, a[maxn];
    Bigint(int x = 0) {
        memset(a, 0, sizeof(a));
        for (len = 1; x; len++)
            a[len] = x % 10, x /= 10;
        len--;
    }
    int &operator[](int i) {
        return a[i];
    }
    void flatten(int L) {
        len = L;
        for (int i = 1; i <= len; i++)
            a[i + 1] += a[i] / 10, a[i] %= 10;
        for (; !a[len]; )
            len--;
    }
    void print() {
        for (int i = max(len, 1); i >= 1; i--)
            printf("%d", a[i]);
    }
};
Bigint operator+(Bigint a, Bigint b) {
    Bigint c;
    int len = max(a.len, b.len);
    for (int i = 1; i <= len; i++)
        c[i] += a[i] + b[i];
    c.flatten(len + 1);
    return c;
}
Bigint dp[maxn];
int n;
int main() {
    cin >> n;
    dp[1] = Bigint(1);
    dp[2] = Bigint(2);
    for(int i = 3; i <= n ;i++){
        dp[i] = dp[i - 1] + dp[i - 2]; 
    }
    dp[n].print();
    return 0;
}

by Crab_Tang @ 2024-07-12 13:54:51

@greyandking @cycycy0530 还是我的更好一点。https://www.luogu.com.cn/paste/l09x6nzu


by Crab_Tang @ 2024-07-12 13:55:20

@cycycy0530 主程序改改就行了。


by wujunxi206 @ 2024-07-12 14:02:22

@cycycy0530
云粘贴板


by wujunxi206 @ 2024-07-12 14:03:19

@cycycy0530
云粘贴板


by yangyang826 @ 2024-07-12 14:07:15

@wujunxi206 “云粘贴板”


by cycycy0530 @ 2024-07-12 19:05:13

@Crab_Tang 好代码 看的蒟蒻似了


by Crab_Tang @ 2024-07-12 21:08:16

@cycycy0530 大哥我注释打成这个样子了还看不懂只能说明不会压位思想或者不会高精度或者不会struct或者不会private或者不会operator...


by cycycy0530 @ 2024-07-13 08:37:22

@Crab_Tang 我本来就是蒟蒻啊


|