3527: [Zjoi2014]力
Time Limit: 30 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 2803 Solved: 1698
[Submit][Status][Discuss]
Description
Input
Output
n行,第i行输出Ei。与标准答案误差不超过1e-2即可。
Sample Input
4006373.885184
15375036.435759
1717456.469144
8514941.004912
1410681.345880
Sample Output
3439.793
7509018.566
4595686.886
10903040.872
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 500010; const double pai = acos(-1.0); double a[maxn],b[maxn],ans[maxn]; int n,len; struct node { double real, imag; node(double real = 0.0, double imag = 0.0) { this->real = real, this->imag = imag; } node operator - (const node&elem) const { return node(this->real - elem.real, this->imag - elem.imag); } node operator + (const node&elem) const { return node(this->real + elem.real, this->imag + elem.imag); } node operator * (const node&elem) const { return node(this->real * elem.real - this->imag * elem.imag, this->real * elem.imag + this->imag * elem.real); } void set(double real = 0.0, double imag = 0.0) { this->real = real, this->imag = imag; } } A[maxn],B[maxn]; void pre1() { len = 1; while(len < (n << 1)) len <<= 1; for (int i = 0; i < n; i++) A[i].set(a[i],0),B[i].set(b[i],0); for (int i = n; i < len; i++) A[i].set(),B[i].set(); } void pre2() { len = 1; while(len < (n << 1)) len <<= 1; for (int i = 0; i < len; i++) A[i].set(),B[i].set(); for (int i = 0; i < n; i++) { A[i].set(a[n - i - 1],0); if (i) B[i].set(b[i],0); } for (int i = n; i < len; i++) A[i].set(),B[i].set(); } void Swap(node &a,node &b) { node temp = a; a = b; b = temp; } void zhuan(node *y) { for (int i = 1, j = len >> 1,k; i < len - 1; i++) { if (i < j) Swap(y[i],y[j]); k = len >> 1; while (j >= k) { j -= k; k >>= 1; } if (j < k) j += k; } } void FFT(node *y,int op) { zhuan(y); for (int h = 2; h <= len; h <<= 1) { node temp(cos(2 * pai * op / h),sin(2 * pai * op / h)); for (int i = 0; i < len; i += h) { node W(1,0); for (int j = i; j < i + h / 2; j++) { node u = y[j],v = W * y[j + h / 2]; y[j] = u + v; y[j + h / 2] = u - v; W = W * temp; } } } if (op == -1) for (int i = 0; i < len; i++) y[i].real /= len; } void solve(node *A,node *B) { FFT(A,1); FFT(B,1); for (int i = 0; i < len; i++) A[i] = A[i] * B[i]; FFT(A,-1); } int main() { scanf("%d",&n); for (int i = 0; i < n; i++) scanf("%lf",&a[i]); for (int i = 1; i < n; i++) b[i] = 1.0 / i / i; pre1(); solve(A,B); for (int i = 0; i < n; i++) ans[i] = A[i].real; pre2(); solve(A,B); for (int i = 0; i < n; i++) ans[i] -= A[n - i - 1].real; for (int i = 0; i < n; i++) printf("%.3lf\n",ans[i]); return 0; }