首页 > 代码库 > BZOJ 3527: [Zjoi2014]力
BZOJ 3527: [Zjoi2014]力
3527: [Zjoi2014]力
Time Limit: 30 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 1545 Solved: 900
[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
Source
额,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 complex16 {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
BZOJ 3527: [Zjoi2014]力
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。