18 条题解
-
1Jerry LV 6 @ 2023-8-31 22:15:10
#include<bits/stdc++.h> #include<queue> #include<set> #include<stack> #include<vector> #define ll long long using namespace std; const int N=1e5+10; const int M=2023; const int inf=0x3f3f3f3f; int n,vis[N]; int dfs(int x) { if(vis[x]!=0)return vis[x]; if(x1 or x2)return 1; return vis[x]=dfs(x-1)+dfs(x-2); } int main() { cin>>n; cout<<dfs(n); return 0; }
-
12023-2-10 20:21:08@
#include <bits/stdc++.h> using namespace std; #define LL long long int main() { int n; LL a[100000]; a[0] = 0; a[1] = 1; cin >> n; int m; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + a[i - 2]; m = i; } cout << a[m]; return 0; }
-
02024-9-6 22:08:05@
#include<bits/stdc++.h> using 内亩死被死 std; int main(){ 因特 n,m,a[103],cnt=0; cin>>n; a[1]=a[2]=?; for( i=?;i<=? i??){ a[i]=a[i-1]+a[i-2]; } cout<<a[n]; }
我看你们有多懒!!!
-
02024-7-24 12:54:01@
666代码 (一维数组解法):
#include<bits/stdc++.h> unsigned long long n,a[10001],i=1; int main() { std::cin>>n; a[i]=1; i++; a[i]=1; int g=2,h=1; for(int i=3;i<=n;i++){ a[i]=a[g]+a[h]; g++; h++; } std::cout<<a[n]; }
-
02024-3-19 16:55:29@
#include <iostraem> using namespace std; int main() { int a, z; cin>>a>>z; if (a>= 10 && z >= 20 ) ``` ``` { cout<<1; } else { cout<<0; } return 0; ``` } ``` 我就看谁傻傻地直接超题解 ``` ```
-
02023-8-6 19:02:11@
#include<bits/stdc++.h> #include<queue> #include<set> #include<stack> #include<vector> #define ll long long using namespace std; const int N=1e5+10; const int M=2023; const int inf=0x3f3f3f3f; int n,vis[N]; int dfs(int x) { if(vis[x]!=0)return vis[x]; if(x==1 or x==2)return 1; return vis[x]=dfs(x-1)+dfs(x-2); } int main() { cin>>n; cout<<dfs(n); return 0; }
记忆化搜索,如f(100)=f(99)+f(98) f(99)=f(98)+f(97) f(98)=f(97)+f(96) 可以看到重复了 所以同一种f(n)答案都一样不需要再重新搜索。
-
-12023-4-9 12:28:46@
细节众多的一个题解!k首先不能等于0,还有就是要把数列开头的1算上,代码如下:
#include<iostream> using namespace std; int jia=1,jie=1,k,sum; int main() { cin>>k; if(k==0) cout<<"no answer!"; else if(k<=2 && k>0) { cout<<"1"; } else { for(int i=1;i<=k-2;i++) { sum=jie+jia; if(i%2==1) jie=sum; else if(i%2==0) jia=sum; } cout<<sum; } return 0; }
-
-12023-4-2 10:25:33@
#include<cstdio> using namespace std; long long n, a[50], tmp; int main() { cin >> n; a[1] = 1; a[2] = 1; for(int i = 3; i <= n; i++){ a[i]=a[i-1]+a[i-2]; } cout << a[n]<< " "; return 0; }
-
-12023-3-13 17:30:43@
#include <bits/stdc++.h> using namespace std; #define LL long long int main() { int n; LL a[100000]; a[0] = 0; a[1] = 1; cin >> n; int m; for (int i = 2; i <= n; i++) { a[i] = a[i - 1] + a[i - 2]; m = i; } cout << a[m]; return 0; }
-
-22023-3-31 19:26:33@
#include <iostream> using namespace std; int main() { int n,a=1,b=1,c=1; cin>>n; for(int i=3; i<=n; i++) { c=a+b; a=b; b=c; } cout<<c; return 0; }
col1 col2 col3 -
-22022-12-17 16:19:55@
#include <iostream> using namespace std;int main(){int n;cin >> n;int a,b,c;a=b=c=1;for(int i=3;i<=n;i++){c=a+b;a=b;b=c;}cout<<c<<endl;}
-
-22022-1-8 10:37:46@
#include <iostream> using namespace std; int main() { int n; cin >> n; int a,b,c; a = b = c = 1; for(int i = 3; i <= n ; i++) { c = a+b; a = b; b = c; } cout << c << endl; }
-
-32023-1-29 21:42:45@
#include<bits/stdc++.h> using namespace std; int main() { int a = 1 , b = 1 , c; cin >> c; int sum; for(int i = 3 ; i <= c ; i++) { sum = a + b; a = b; b = sum; } cout << b; }
-
-52022-10-31 15:27:48@
#include<iostream> #include<stdio.h> using namespace std; int main(){ int k,o=1,t=1,z=2; cin>>k; for(int i=3;i<=k;i++){ z=o+t; o=t; t=z; } if(k<3){ cout<<1;//k小于3的情况 return 0; } printf("%d",z); }
-
-52022-1-8 10:20:33@
#include <stdio.h> #include <iostream> using namespace std; int main() { int n; cin >> n; int a,b,c; a = b = c = 1; for(int i = 3 ; i <= n ; i++) { c = a + b; a = b; b = c; } cout << c << endl; } // 1 1 2 3 5 8 13 21 34...... // a[i] = a[i-1] + a[i-2]
-
-62022-10-24 18:37:29@
#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 x) { if(x == 1 || x == 2) { return 1; } return f(x - 1) + f(x - 2); } signed main() { int n; cin >> n; cout << f(n) << endl; }*/ int n; signed main() { cin >> n; int a, b, c; a = b = c = 1; for(int i = 3; i <= n; i++) { c = a + b; a = b; b = c; } cout << c << endl; }
数据可能有一点点大
-
-102022-1-8 10:22:07@
#include <iostream> #include <math.h> #include <iomanip> using namespace std; int main() { int n; cin >> n; int a,b,c; a = b = c = 1; for(int i = 3; i <= n ; ++i) { c = a + b; a = b; b = c; } cout << c << endl; }
-
-132022-1-8 10:23:34@
#include <stdio.h> #include <iostream> using namespace std; int main() { int n; cin >> n; int a,b,c; a = b = c = 1; for (int i = 3;i<= n; i++) { c = a + b; a = b; b = c; } cout << c << endl; }
- 1
信息
- ID
- 904
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 702
- 已通过
- 323
- 上传者