给出n个数qi,给出Fj的定义如下:
令Ei=Fi/qi,求Ei.
标签:get nbsp 表示 source page net discus cst blank
n行,第i行输出Ei。与标准答案误差不超过1e-2即可。
额,FFT是真的不会,卷积是真的不熟,wzq_QwQ的题解是真的好。
首先把$q_{i}$除到右边,然后上下约掉,然后,发现有规律,然后构造函数,请移步wzq_QwQ的题解吧,懒得抄了。
1 #include <cmath> 2 #include <cstdio> 3 #include <iostream> 4 5 const int siz = 600005; 6 const double pi = acos(-1); 7 8 inline double sqr(double x) { 9 return x * x; 10 } 11 12 int n, rev[siz]; 13 double num[siz]; 14 15 struct complex 16 { 17 double r, i; 18 19 inline complex(double a = 0, double b = 0) 20 : r(a), i(b) {}; 21 inline complex operator + (const complex &a) { 22 return complex(r + a.r, i + a.i); 23 } 24 inline complex operator - (const complex &a) { 25 return complex(r - a.r, i - a.i); 26 } 27 inline complex operator * (const complex &a) { 28 return complex(r*a.r - i*a.i, r*a.i + i*a.r); 29 } 30 }a[siz], b[siz]; 31 32 inline void FFT(complex *s, int k) 33 { 34 for (int i = 0; i < n; ++i) 35 if (i < rev[i]) 36 std::swap(s[i], s[rev[i]]); 37 38 for (int h = 2; h <= n; h <<= 1) 39 { 40 complex wn(cos(2*pi*k/h), sin(2*pi*k/h)); 41 for (int i = 0; i < n; i += h) 42 { 43 complex w(1, 0); 44 for (int j = 0; j < (h >> 1); ++j, w = w*wn) 45 { 46 complex t = s[i + j + (h >> 1)]*w; 47 s[i + j + (h >> 1)] = s[i + j] - t; 48 s[i + j] = s[i + j] + t; 49 } 50 } 51 } 52 53 if (k == -1) 54 for (int i = 0; i < n; ++i) 55 s[i].r = s[i].r / n; 56 } 57 58 signed main(void) 59 { 60 scanf("%d", &n); --n; 61 62 for (int i = 0; i <= n; ++i) 63 scanf("%lf", &a[i].r); 64 65 for (int i = 0; i < n; ++i) 66 b[i].r = -1.0 / sqr(n - i); 67 68 for (int i = n + 1; i <= 2*n; ++i) 69 b[i].r = -1.0 * b[2*n - i].r; 70 71 int m = n, k = n << 2, len = 0; 72 73 for (n = 1; n <= k; n <<= 1)++len; 74 75 for (int i = 0; i < n; ++i) 76 rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1)); 77 78 FFT(a, 1); 79 FFT(b, 1); 80 81 for (int i = 0; i <= n; ++i) 82 a[i] = a[i] * b[i]; 83 84 FFT(a, -1); 85 86 for (int i = m; i <= 2*m; ++i) 87 printf("%lf\n", a[i].r); 88 }
@Author: YouSiki
标签:get nbsp 表示 source page net discus cst blank
原文地址:http://www.cnblogs.com/yousiki/p/6266368.html