bzoj3527

http://www.lydsy.com/JudgeOnline/problem.php?id=3527

今天肿么这么颓废啊。。。心态崩了

首先我们得出Ei=Fi/qj,然后我们设f[i]=1/i/i,那么我们把刚才的式子转化一下,就是ans[j]=f[i]*g[j-i]-f[i]*g[i-j](sigma省略了)前面的东西是一个卷积,但是后面的东西加出来是一个2*i-j,不是一个固定的值,那么我们翻转一下第二个g,变成了-f[i]*g[n-i+j],现在i+n-i+j=n+j是一个固定的值(似乎固定是指在当前sigma下是固定的就可以了),那么就好了。

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
const int N = 300010;
int n, m, l;
int r[N];
complex<double> a[N], b[N], q[N];
void fft(complex<double> *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)
    {
        complex<double> w(cos(pi / i), f * sin(pi / i));
        for(int p = i << 1, j = 0; j < n; j += p)
        {
            complex<double> wn(1, 0);
            for(int k = 0; k < i; ++k, wn *= w)
            {
                complex<double> x = a[j + k], y = wn * a[j + k + i];
                a[j + k] = x + y; a[j + k + i] = x - y; 
            }
        }
    }
    if(f == -1) for(int i = 0; i <= n; ++i) a[i] /= n;
}
int main()
{
    scanf("%d", &n); --n; m = 2 * n;
    for(int i = 0; i <= n; ++i) 
    {
        double x; scanf("%lf", &x); 
        if(i > 0) a[i] = b[n - i] = 1.0 / (double)i / (double)i;
        else a[i] = b[n - i] = 0;
        q[i] = x;
    }
    for(n = 1; n <= m; n <<= 1) ++l;
    for(int i = 0; i <= n; ++i) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
    fft(a, 1); fft(b, 1); fft(q, 1);
    for(int i = 0; i <= n; ++i) a[i] = q[i] * a[i], b[i] = q[i] * b[i];
    fft(a, -1); fft(b, -1);
    for(int i = 0; i <= m / 2; ++i) printf("%.3f\n", a[i].real() - b[i + m / 2].real());    
    return 0;
}
View Code

 

posted @ 2017-05-18 20:12  19992147  阅读(319)  评论(0编辑  收藏  举报