bzoj3527: [Zjoi2014]力
http://www.lydsy.com/JudgeOnline/problem.php?id=3527
给出n个数qi,给出Fj的定义如下:
令Ei=Fi/qi,求Ei.
以n=4为例:
设数组a[],b[]
令c[]=a[]反转
y[]=c[]*b[]
那么E[i]=x[i]-y[n-i-1]
#include<cmath> #include<cstdio> #include<algorithm> using namespace std; #define N 100001 const int M=1<<18; const double pi=acos(-1); struct Complex { double x,y; Complex() { } Complex(double _x,double _y) : x(_x),y(_y) { } Complex operator + (Complex & P) { Complex C; C.x=x+P.x; C.y=y+P.y; return C; } Complex operator - (Complex & P) { Complex C; C.x=x-P.x; C.y=y-P.y; return C; } Complex operator * (Complex & P) { Complex C; C.x=x*P.x-y*P.y; C.y=x*P.y+y*P.x; return C; } }; typedef Complex E; int n; int r[M]; E b[M]; E x[M],y[M]; void fft(E *a,int f) { for(int i=0;i<n;++i) if(i<r[i]) swap(a[i],a[r[i]]); for(int i=1;i<n;i<<=1) { E wn(cos(pi/i),f*sin(pi/i)); for(int p=i<<1,j=0;j<n;j+=p) { E w(1,0); for(int k=0;k<i;++k,w=w*wn) { E x=a[j+k],y=w*a[j+k+i]; a[j+k]=x+y; a[j+k+i]=x-y; } } } } int main() { int m,t; scanf("%d",&n); n--; m=t=n; double p; for(int i=0;i<=n;++i) { scanf("%lf",&p); x[i].x=p; y[n-i].x=p; } for(int i=1;i<=t;++i) b[i].x=1.0/i/i; m+=n; int bit=0; for(n=1;n<=m;n<<=1) bit++; for(int i=0;i<n;++i) r[i]=(r[i>>1]>>1)|((i&1)<<bit-1); fft(b,1); fft(x,1); for(int i=0;i<n;++i) x[i]=x[i]*b[i]; fft(x,-1); fft(y,1); for(int i=0;i<n;++i) y[i]=y[i]*b[i]; fft(y,-1); for(int i=0;i<=t;++i) printf("%.3lf\n",(x[i].x-y[t-i].x)/n); }