标签:struct splay one ide == read wap tor str
给出两个高精度数
长度在10000以内
快速傅里叶的运用
把a1*x^0+a2*x^1+a3*x^2+......+an+1*x^n看做a1*10^0+a2*10^1+a3*10^2+.....+an+1*10^n
上快速傅里叶即可
1 #include <bits/stdc++.h> 2 inline int read(){ 3 int x=0;int f=1;char ch=getchar(); 4 while(!isdigit(ch)) {if(ch==‘-‘) f=-1;ch=getchar();} 5 while(isdigit(ch)) {x=x*10+ch-‘0‘;ch=getchar();} 6 return x*f; 7 } 8 const int MAXN=1e6+10; 9 const double pi=acos(-1); 10 int R[MAXN],L,H; 11 long long ans[MAXN]={}; 12 struct complex{ 13 double r,v; 14 complex(double a=0,double b=0):r(a),v(b){} 15 inline complex operator + (const complex &b) {return complex(r+b.r,v+b.v);} 16 inline complex operator * (const complex &b) {return complex(r*b.r-v*b.v,r*b.v+v*b.r);} 17 inline complex operator - (const complex &b) {return complex(r-b.r,v-b.v);} 18 }a[MAXN],b[MAXN],w[MAXN]; 19 inline void swap(complex& a,complex& b) {complex t(a);a=b;b=t;} 20 inline void FFT(complex *a,int f){ 21 for(int i=0;i<L;i++){ 22 if(i<R[i]) swap(a[i],a[R[i]]); 23 } 24 for(int len=2;len<=L;len<<=1){ 25 int l=len>>1; 26 complex wn(cos(pi/l),f*sin(pi/l)); 27 for(int i=1;i<l;i++){ 28 w[i]=w[i-1]*wn; 29 } 30 for(int st=0;st<L;st+=len){ 31 for(int k=0;k<l;k++){ 32 complex x=a[st+k];complex y=w[k]*a[st+k+l]; 33 //printf("%lf %lf\n",x.r,x.v); 34 a[st+k]=x+y;a[st+k+l]=x-y; 35 } 36 } 37 } 38 if(f==-1){ 39 for(int i=0;i<L;i++){ 40 a[i].r=a[i].r/L; 41 } 42 } 43 } 44 char ch1[300010],ch2[300010]; 45 int main(){ 46 w[0].r=1; 47 scanf("%s%s",ch1+1,ch2+1); 48 int n=strlen(ch1+1); int m=strlen(ch2+1); 49 for(int len=0,i=n;i;i--,len++) a[len]=ch1[i]-‘0‘; 50 for(int len=0,i=m;i;i--,len++) b[len]=ch2[i]-‘0‘; 51 L=1; 52 while(L<n+m) L<<=1,H++; 53 for(int i=0;i<L;i++){ 54 R[i]=(R[i>>1]>>1)|((i&1)<<(H-1)); 55 } 56 FFT(a,1);FFT(b,1); 57 for(int i=0;i<L;i++){ 58 a[i]=a[i]*b[i]; 59 } 60 FFT(a,-1); 61 for(int i=0;i<n+m-1;i++){ 62 ans[i]=1LL*(a[i].r+0.5); 63 } 64 int len=300000; 65 for(int i=0;i<=len;i++){ 66 ans[i+1]+=ans[i]/10; 67 ans[i]%=10; 68 } 69 while(ans[len]==0) len--; 70 for(int i=len;i>=0;i--){ 71 printf("%lld",ans[i]); 72 } 73 return 0; 74 }
标签:struct splay one ide == read wap tor str
原文地址:http://www.cnblogs.com/something-for-nothing/p/7892161.html