BZOJ 1002: [FJOI2007]轮状病毒 []
我也不知道该说点什么好
难道bzoj不支持重载运算符?洛谷AC bzoj WA
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; const int N=100; int n; struct Big{ int d[N],l; int& operator [](int x){return d[x];} Big(){l=1;memset(d,0,sizeof(d));} }f[105]; Big operator *(Big a,int b){ int g=0; for(int i=1;i<=a.l;i++){ g+=a[i]*b; a[i]=g%10; g/=10; } for(;g;g/=10) a[++a.l]=g%10; return a; } Big operator -(Big a,Big b){ for(int i=1;i<=b.l;i++){ if(a[i]<b[i]) a[i]+=10,a[i+1]--; a[i]-=b[i]; } int p=b.l+1; while(a[p]<0) a[p]+=10,a[p+1]--; while(a[a.l]==0) a.l--; return a; } Big operator +(Big a,int b){ int g=b,i=1; for(;g;i++) g+=a[i],a[i]=g%10,g/=10; a.l=max(a.l,i); return a; } void print(Big &a){ for(int i=a.l;i>=1;i--) printf("%d",a[i]); } int main(){ scanf("%d",&n); f[1].l=1;f[1][1]=1; f[2].l=1;f[2][1]=5; for(int i=3;i<=n;i++) f[i]=f[i-1]*3-f[i-2]+2; print(f[n]); }
Copyright:http://www.cnblogs.com/candy99/