2016-06-01 21:36:44
Title: http://www.lydsy.com/JudgeOnline/problem.php?id=3527
I'm just a big, dumb, smiling face.
1#include <bits/stdc++.h>2 #defineINF 10000000003 #definell Long Long4 #defineN 5000055 using namespacestd;6 intRead () {7 intx=0, f=1;CharCh=GetChar ();8 while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}9 while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();}Ten returnx*F; One } A Const DoublePi=acos (-1.0); - structcd{ - Doublex, y; theCD (DoubleA=0,Doubleb=0) {x=a,y=b;} -Friend CDoperator+ (CD n1,cd n2) {returnCD (n1.x+n2.x,n1.y+n2.y);} -Friend CDoperator-(CD n1,cd n2) {returnCD (n1.x-n2.x,n1.y-n2.y);} -Friend CDoperator* (CD n1,cd n2) {returnCD (n1.x*n2.x-n1.y*n2.y,n1.x*n2.y+n1.y*n2.x);} + }; - CD A[n],b[n],c[n],d[n]; + intN,nn,bit; A DoubleQ[n]; at voidFFT (CD *a,intNinttype) { - for(intI=0, j=0; i<n;i++){ - if(j>i) swap (a[i],a[j]); - intk=N; - while(j& (k>>=1)) j&=~K; -j|=K; in } - for(intI=1; i<=bit;i++){ toCD w_n (cos (2*type*pi/(1<<i)), Sin (2*type*pi/(1<<i))); + for(intj=0;j< (1<<bit); j+= (1<<i)) { -CD W (1,0); the for(intk=j;k<j+ (1<< (I-1)); k++){ *CD tmp=a[k],tt=w*a[k+ (1<< (I-1))]; $a[k]=tmp+tt;a[k+ (1<< (I-1))]=tmp-tt;Panax Notoginsengw=w*W_n; - } the } + } A if(type<0) for(intI=0; i<n;i++) a[i].x=a[i].x/N; the } + intMain () { -N=read (); nn=N; $ for(intI=0; i<n;i++) scanf ("%LF", &q[i]), A[I]=CD (Q[i],0); $ for(intI=1; i<n;i++) b[i].x=1.0/(Double) (I*i), b[i].y=0; -n=2*n-1; bit=1; - while((1<<bit) <n) bit++; then=1<<bit; -b[0]=CD ();Wuyi for(inti=nn;i<n;i++) A[I]=CD (), b[i]=CD (); the -FFT (A,n,1); FFT (B,n,1); Wu for(intI=0; i<n;i++) c[i]=a[i]*B[i]; -FFT (c,n,-1); About for(intI=0; i<nn;i++) A[I]=CD (q[nn-i-1],0); $ for(inti=nn;i<n;i++) a[i]=CD (); -FFT (A,n,1); - for(intI=0; i<n;i++) d[i]=a[i]*B[i]; -FFT (d,n,-1); A + for(intI=0; i<nn;i++) c[i].x-=d[nn-i-1].x; the for(intI=0; i<nn;i++) printf ("%.5lf\n", c[i].x); - return 0; $ } the
View Code
"bzoj3527" [Zjoi2014] Force FFT