高精20求调
  • 板块P1255 数楼梯
  • 楼主GOlize
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/1/18 09:21
  • 上次更新2025/1/18 12:41:35
查看原帖
高精20求调
1378206
GOlize楼主2025/1/18 09:21
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
struct bign{
	int len,d[N];
	bign(){len=1; memset(d,0,sizeof(d));}
	bign(int x){
		memset(d,0,sizeof(d));
		for (len=0;x;x/=10)
			d[len++]=x%10;
		if (len==0) len=1;
	} 
	string str(){
		string s;
		for (int i=len-1;i>=0;i--)
			s+=(char)('0'+d[i]);
		return s;
	}
	bign operator +(bign b){
		bign c;
		c.len=max(len,b.len);
		for (int i=0;i<c.len;i++){
				c.d[i]+=d[i]+b.d[i];
				c.d[i+1]+=c.d[i]/10;
				c.d[i]%=10;
		}
		if (c.d[c.len]>0) c.len++;
		return c; 
	}
	friend ostream& operator <<(ostream &output,bign x){
		output<<x.str();
		return output;
	}
};
int main(){
	int n;
	bign f[5005];
	f[1]=1;
	f[2]=2;
	for (int i=3;i<=n;i++)
		f[i]=f[i-1]+f[i-2];
	cin>>n;
	cout<<f[n];
	return 0;
}
2025/1/18 09:21
加载中...