60分玄关!!!!!!!!!!

P1255 数楼梯

qaz12345678_ @ 2024-07-27 13:31:43

#include <iostream>
using namespace std;
long long f[1005];
int n;
int main()
{
    cin >> n;
    f[1] = 1;
    f[2] = 2;
    for (int i = 3;i <= n;i++)
    {
        f[i] = f[i - 1] + f[i - 2];
    }
    cout << f[n];
}

by dzhjntm @ 2024-07-27 13:35:26

要用高精度


by yhwangzixuan @ 2024-07-27 13:57:54

@qaz12345678_ 用高精或者用python写


by 枫原万叶 @ 2024-07-27 15:59:23

@qaz12345678_ 数据太大,要写高精

#include<bits/stdc++.h>
using namespace std;
int a[5000],b[5000],c[5000];
int main()
{
    int n;
    int x=1;
    cin>>n;
    if(n<3)
    {
        cout<<n;
        return 0;
    }
    a[1]=1;b[1]=2;
    for(int i=3;i<=n;i++)
    {
        for(int j=1;j<=x;j++)
            c[j]=a[j]+b[j];
        for(int j=1;j<=x;j++)
        {
            if(c[j]>9)
            {
                c[j+1]=c[j+1]+c[j]/10;
                c[j]%=10;
                if(j+1>x)
                    x++;
            }
        }
        for(int j=1;j<=x;j++)
            a[j]=b[j];
        for(int j=1;j<=x;j++)
            b[j]=c[j];
    }
    for(int i=x;i>0;i--)
        cout<<b[i];
    return 0;
}

by qaz12345678_ @ 2024-07-27 17:21:06

@dzhjntm
@yhhuangzixuan
@luogu_cyx

感谢帮助!


|