8 条题解

  • 1
    @ 2026-4-17 19:34:19

    包不AC

    #include<bits/stdc++.h>
    using namespace std;
    const int N=50+5;
    long long f[N],n;
    int main(){
    	f[1]=1;
    	f[0]=1;
    	for(int i=2;i<=50;i++)
    	    f[i]=f[i-1]+f[i-2];
    	cin>>n;
    	while(n){
    		cout<<f[n]<<endl;
    		cin>>n;
    	}
    	return 0;
    }
    
    • 1
      @ 2025-11-30 14:27:34

      亲测AC

      #include<bits/stdc++.h>
      using namespace std;
      const int N=1e5+10;
      int n[55];
      int f(int a){
      	if(a==51){
      		return 0;
      	}
      	n[a]=n[a-1]+n[a-2];
      	return f(a+1);
      }
      int main(){
      	n[0]=1;
      	n[1]=1;
      	f(2);
      	int x;
      	while(true){
      		cin>>x;
      		if(x==0){
      			return 0;
      		}
      		cout<<n[x]<<endl;
      	}
      }
      
      • 1
        @ 2025-11-22 15:52:37

        包AC

        方法1

        #include<bits/stdc++.h>
        using namespace std;
        int a,aa[1010];
        int main(){
            aa[0]=1;
            aa[1]=1;
            aa[2]=2;
            for(int i=3; i<20; i++){
                aa[i]=(aa[i-1]+aa[i-2]+aa[i-3]);
            }
            while(cin >> a) {
                if(a==0) break;
                cout << aa[a] << endl;
                
            }
            return 0;
        }
        

        方法2

        #include<bits/stdc++.h>
        using namespace std;
        int f(int n){
        	if(n==1)return 1;
        	if(n==2)return 2;
        	return f(n-1)+f(n-2);
        } 
        int n,m;
        int main(){
        	while(cin >> n){
        		if(n==0) return 0;
        		cout<<f(n) << "\n";
        	}
        	return 0;
        }
        
        
        • 0
          @ 2024-10-16 21:01:29

          史上最简代码

          using namespace std;
          int f(int n){
          	if(n==1)return 1;
          	if(n==2)return 2;
          	return f(n-1)+f(n-2);
          } 
          int n;
          int main(){
          	cin>>n;
          	cout<<f(n);
          }
          
        • 0
          @ 2024-5-19 18:04:58

          最简代码

          #include<bits/stdc++.h>
          using namespace std;
          
          long long a;
          
          int sb(int n){
          	if(n==0||n==1)return 1;
          	return sb(n-1)+sb(n-2);
          }
          
          int main(){
          	while(cin>>a&&a!=0)cout<<sb(a)<<endl;
          	return 0;
          }
          
          • 0
            @ 2024-5-19 17:56:23

            #include #include #include #include #include #include using namespace std; const int N=1e6+10; const int INF=0x3f3f3f3f; int n,k,a[N]; void f() { a[1]=1,a[2]=2; for(int i=3;i<=50;i++) a[i]=a[i-1]+a[i-2]; } int main(){ f(); while(cin>>k) { if(k==0) break; else cout<<a[k]<<endl; } return 0; }

            • 0
              @ 2022-12-11 10:36:26

              看到TLE把我吓了一跳...... 于是

              #include <iostream>
              #include <stack>
              #include <cmath>
              #include <vector>
              #include <string.h>
              #include <queue>
              #include <stdio.h>
              #include <iomanip>
              #include <cstdio>
              #include <algorithm>
              #define int long long
              using namespace std;
              const int N = 1e5 + 10;
              const int INF = 0x3f3f3f3f;
              int f(int n)
              {
                  if(n == 0 || n == 1)
                  {
                      return 1;
                  }
                  else if(n == 2) return 2;
                  else if(n == 3) return 3;
                  else if(n == 4) return 5;
                  else if(n == 5) return 8;
                  return f(n - 1) + f(n - 2);
              }
              signed main()
              {
              	int n;
                  while(cin >> n && n != 0)
                  {
                      cout << f(n) << endl;
                  }
              	return 0;
              }
              
              • -1
                @ 2024-5-19 19:40:58
                #include<set>
                #include<string> 
                #include<cstring>
                #include<algorithm>
                using namespace std;
                const int N=1e6+10;
                const int INF=0x3f3f3f3f;
                int n,k,a[N];
                void f() { 
                	a[1]=1,a[2]=2; 
                	for(int i=3;i<=50;i++) 
                	a[i]=a[i-1]+a[i-2]; 
                } 
                int main(){ 
                	f(); 
                	while(cin>>k)
                	{ 
                	if(k==0) break; 
                	else cout<<a[k]<<endl; 
                	} 
                	return 0;
                }
                
                • 1

                信息

                ID
                1595
                时间
                1000ms
                内存
                256MiB
                难度
                6
                标签
                递交数
                529
                已通过
                163
                上传者