BZOJ 3527: [Zjoi2014]力 [快速傅里叶变换]

 

给出n个数qi,给出Fj的定义如下:
令Ei=Fi/qi,求Ei.
 

找到一个很详细的题解:http://blog.csdn.net/qq_33929112/article/details/54590319

花了两个小时来理解和写,1个小时查卡精度,又花了1个小时改模板卡洛谷的时限

以后都从0开始

观察这个式子

E=C-D

就是两个卷积啊....其中一个函数是1/i^2

规定1/0^2=0后,i=j也可以包括进来了 然后前面那个是卷积标准形式,后面那个和上一题的技巧是一样的更改求和指标然后把q反转再反转D
以前的推导

[update 2017-03-30]

新推♂倒了一下

写出E的表达式,定义$frac{1}{0^2}=0$前半部分裸卷积,后半部分反转一个向量,又是裸卷积...

注意:

傻逼题卡精度1/i/i才行

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=(1<<18)+5, INF=1e9;
const double PI=acos(-1);
inline int read(){
    char c=getchar();int x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

struct meow{
    double x, y;
    meow(double a=0, double b=0):x(a), y(b){}
};
meow operator +(meow a, meow b) {return meow(a.x+b.x, a.y+b.y);}
meow operator -(meow a, meow b) {return meow(a.x-b.x, a.y-b.y);}
meow operator *(meow a, meow b) {return meow(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);}
meow conj(meow a) {return meow(a.x, -a.y);}
typedef meow cd;

struct FFT{
    int n, rev[N];
    void ini(int lim) {
        n=1; int k=0;
        while(n<lim) n<<=1, k++;
        for(int i=0; i<n; i++) {
            int t=0;
            for(int j=0; j<k; j++) if(i&(1<<j)) t |= (1<<(k-1-j));
            rev[i]=t;
        }
    }
    void dft(cd *a, int flag) {
        for(int i=0; i<n; i++) if(i<rev[i]) swap(a[i], a[rev[i]]);
        for(int l=2; l<=n; l<<=1) {
            int m=l>>1; 
            cd wn = meow(cos(2*PI/l), flag*sin(2*PI/l));
            for(cd *p=a; p!=a+n; p+=l) {
                cd w(1, 0);
                for(int k=0; k<m; k++) {
                    cd t = w*p[k+m];
                    p[k+m] = p[k] - t;
                    p[k] = p[k] + t;
                    w=w*wn;
                }
            }
        }
        if(flag==-1) for(int i=0; i<n; i++) a[i].x/=n;
    }
}fft;

int n;
cd a[N], b[N], c[N];
int main() {
    freopen("in","r",stdin);
    n=read(); double x;
    for(int i=0; i<n; i++) scanf("%lf",&x), a[i].x=b[n-1-i].x=x;
    for(int i=1; i<n; i++) c[i].x=1.0/i/i;
    fft.ini(n+n-1);
    fft.dft(a, 1); fft.dft(b, 1); fft.dft(c, 1);
    for(int i=0; i<fft.n; i++) a[i]=a[i]*c[i], b[i]=b[i]*c[i];
    fft.dft(a, -1); fft.dft(b, -1);
    for(int i=0; i<n; i++) printf("%lf
", a[i].x-b[n-1-i].x);
}
原文地址:https://www.cnblogs.com/candy99/p/6389298.html