OIbishop @ 2022-08-23 20:08:40
#include <bits/stdc++.h>
using namespace std;
int a[10001];
int main()
{
int n;
long long q = 0;
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];
return 0;
}
by OIbishop @ 2022-08-23 20:09:04
50分
by 7708__qwq @ 2022-08-23 20:10:03
高精
by 7708__qwq @ 2022-08-23 20:10:15
@jyqjyq
by a2lyaXNhbWUgbWFyaXNh @ 2022-08-23 20:14:38
又是一个没有开高精度50分(或使用pyt)的用户
by huihui_qwq @ 2022-08-23 20:23:58
stop learning useless algorithms, use python.
by KarmaticEnding @ 2022-08-23 20:25:12
这边推荐您使用高精度加法
高精加法模板:```cpp
using namespace std; int result[100000],sresult[100000]; char a1[10000],b1[10000]; int a[10000],b[10000],tmp[10000]; int lena,lenb,lenresult; void add(){ int carry=0; while(lenresult+1<=lena||lenresult+1<=lenb){ result[lenresult]=a[lenresult]+b[lenresult]+carry; carry=result[lenresult]/10; result[lenresult]%=10; lenresult++; } result[lenresult]=carry; if(carry==0) lenresult--;
for(int i=lenresult;i>-1;i--){
printf("%d",result[i]);
}
}
int main(){
cin>>a1>>b1;
lena=strlen(a1);
lenb=strlen(b1);
for(int i=0;i<lena;i++) a[lena-i-1]=a1[i]-48;
for(int i=0;i<lenb;i++) b[lenb-i-1]=b1[i]-48;
add();
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(result,0,sizeof(result));
memset(a1,' ',sizeof(a1));
memset(b1,' ',sizeof(b1));
lena=lenb=lenresult=0;
}
当然,这只是单纯的加法,希望您将它融合到题目中去
by huihui_qwq @ 2022-08-23 20:26:53
@light_dream markdown炸了(
by KarmaticEnding @ 2022-08-23 20:28:53
额,不好意思
#include<bits/stdc++.h>
using namespace std;
int result[100000],sresult[100000];
char a1[10000],b1[10000];
int a[10000],b[10000],tmp[10000];
int lena,lenb,lenresult;
void add(){
int carry=0;
while(lenresult+1<=lena||lenresult+1<=lenb){
result[lenresult]=a[lenresult]+b[lenresult]+carry;
carry=result[lenresult]/10;
result[lenresult]%=10;
lenresult++;
}
result[lenresult]=carry;
if(carry==0) lenresult--;
for(int i=lenresult;i>-1;i--){
printf("%d",result[i]);
}
}
int main(){
cin>>a1>>b1;
lena=strlen(a1);
lenb=strlen(b1);
for(int i=0;i<lena;i++) a[lena-i-1]=a1[i]-48;
for(int i=0;i<lenb;i++) b[lenb-i-1]=b1[i]-48;
add();
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(result,0,sizeof(result));
memset(a1,' ',sizeof(a1));
memset(b1,' ',sizeof(b1));
lena=lenb=lenresult=0;
}
可以了吧~