5 条题解

  • 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 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;
      }
      
      • 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

            信息

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