标签:code bit i++ can == -- namespace include struct
题解:
f[i]=(f[i-1]*3+f[i-2]);
高精度计算
代码:
#include<bits/stdc++.h> using namespace std; struct big { int a[101],len; }; int n; big cf(big a,int k) { for (int i=1;i<=a.len;i++)a.a[i]*=k; for (int i=1;i<=a.len;i++) { a.a[i+1]+=a.a[i]/10; a.a[i]%=10; } if (a.a[a.len+1]!=0)a.len++; return a; } big jf(big a,big b) { a.a[1]+=2; int j=1; while (a.a[j]>=10){a.a[j]%=10;a.a[j+1]++;j++;} for (int i=1;i<=a.len;i++) { a.a[i]-=b.a[i]; if(a.a[i]<0){a.a[i]+=10;a.a[i+1]--;} } while (a.a[a.len]==0)a.len--; return a; } int main() { big f[101];f[1].a[1]=1;f[2].a[1]=5; f[1].len=f[2].len=1; scanf("%d",&n); for (int i=3;i<=n;i++)f[i]=jf(cf(f[i-1],3),f[i-2]); for (int i=f[n].len;i;i--)printf("%d",f[n].a[i]); return 0; }
标签:code bit i++ can == -- namespace include struct
原文地址:http://www.cnblogs.com/xuanyiming/p/7787237.html