[Zjoi2014]力
Time Limit: 30 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 2719 Solved: 1656
[Submit][Status][Discuss]
Description
给出n个数qi,给出Fj的定义如下:
令Ei=Fi/qi,求Ei.
Input
第一行一个整数n。
接下来n行每行输入一个数,第i行表示qi。
n≤100000,0<qi<1000000000
Output
n行,第i行输出Ei。与标准答案误差不超过1e-2即可。
Sample Input
5
4006373.885184
15375036.435759
1717456.469144
8514941.004912
1410681.345880
4006373.885184
15375036.435759
1717456.469144
8514941.004912
1410681.345880
Sample Output
-16838672.693
3439.793
7509018.566
4595686.886
10903040.872
3439.793
7509018.566
4595686.886
10903040.872
HINT
https://www.cnblogs.com/iwtwiioi/p/4126284.html
1 #pragma GCC optimize(2) 2 #pragma G++ optimize(2) 3 #include<cstring> 4 #include<cmath> 5 #include<iostream> 6 #include<cstdio> 7 #include<algorithm> 8 9 #define N 300007 10 #define pi acos(-1) 11 using namespace std; 12 inline int read() 13 { 14 int x=0,f=1;char ch=getchar(); 15 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 16 while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} 17 return x*f; 18 } 19 20 int n,m,L; 21 int rev[N]; 22 struct comp 23 { 24 double r,v; 25 inline comp operator+(comp const &a){return (comp){r+a.r,v+a.v};} 26 inline comp operator-(comp const &a){return (comp){r-a.r,v-a.v};} 27 inline comp operator*(comp const &a){return (comp){r*a.r-v*a.v,r*a.v+v*a.r};} 28 }f[N],_f[N],g[N],e1[N],e2[N]; 29 30 void FFT(comp *a,int f) 31 { 32 for (int i=0;i<n;i++)if(i<rev[i])swap(a[i],a[rev[i]]); 33 for (int i=1;i<n;i<<=1) 34 { 35 comp wn=(comp){cos(pi/i),f*sin(pi/i)}; 36 for (int j=0;j<n;j+=(i<<1)) 37 { 38 comp w=(comp){1,0}; 39 for (int k=0;k<i;k++,w=w*wn) 40 { 41 comp x=a[j+k],y=w*a[j+k+i]; 42 a[j+k]=x+y,a[j+k+i]=x-y; 43 } 44 } 45 } 46 if(f==-1)for (int i=0;i<n;i++)a[i].r/=n; 47 } 48 int main() 49 { 50 n=read()-1; 51 for (int i=0;i<=n;i++) 52 { 53 double x;scanf("%lf",&x); 54 f[i].r=_f[n-i].r=x; 55 } 56 for (int i=1;i<=n;i++)g[i].r=(1.0/i/i); 57 m=2*n;for (n=1;n<=m;n<<=1,L++);if(L)L--; 58 for (int i=0;i<n;i++)rev[i]=(rev[i>>1]>>1)|((i&1)<<L); 59 FFT(f,1),FFT(_f,1),FFT(g,1); 60 for (int i=0;i<n;i++)e1[i]=f[i]*g[i],e2[i]=_f[i]*g[i]; 61 FFT(e1,-1),FFT(e2,-1); 62 for (int i=0;i<=m/2;i++) 63 printf("%.7lf ",e1[i].r-e2[m/2-i].r); 64 }