• BZOJ3527: [Zjoi2014]力(FFT)


    题意

    题目链接

    Sol

    直接把(q_i)除掉

    那么(E_j = sum_{i = 1}^{j - 1} q_i frac{1}{(i - j)^2} - sum_{i = j + 1}^n q_i frac{1}{(i - j)^2})

    (f_i = q_i, g_i = frac{1}{i^2})

    带入原式发现原式变成了卷积的形式

    (E_j = f_i g_{i - j})

    然后像(BZOJ2194)那样把(g)给翻转掉,就成了标准卷积形式

    FFT一波

    // luogu-judger-enable-o2
    #include<bits/stdc++.h>
    const double Pi = acos(-1);
    using namespace std;
    const int MAXN = 1e6 + 10;
    int N, M, r[MAXN];
    struct com {
        double x, y;
        com(double xx = 0, double yy = 0) {x = xx; y = yy;}
        com operator + (com &rhs) {
            return com(x + rhs.x, y + rhs.y);
        }
        com operator - (com &rhs) {
            return com(x - rhs.x, y - rhs.y);
        }
        com operator * (com &rhs) {
            return com(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
        }
    }a[MAXN], b[MAXN], c[MAXN];
    void FFT(com *a, int N, int type) {
        for(int i = 0; i < N; i++) if(i < r[i]) swap(a[i], a[r[i]]);
        for(int mid = 1; mid < N; mid <<= 1) {
            com Wn(cos(Pi / mid), type * sin(Pi / mid)); 
            for(int R = mid << 1, j = 0; j < N; j += R) {//这里要写<N 
                com w(1, 0);
                for(int k = 0; k < mid; k++, w = w * Wn) {
                    com x = a[j + k], y = w * a[j + k + mid];
                    a[j + k] = x + y;
                    a[j + k + mid] = x - y;
                }
            }
        }
        if(type == -1) {
            for(int i = 0; i <= N; i++) a[i].x /= N;
        }
    }
    int Mul(com *c, com *a, com *b, int N, int M) {
        int ret = 1, l = 0;
        while(ret <= N + M) ret <<= 1, l++; 
        for(int i = 0; i < ret; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1)  << l - 1);
        FFT(a, ret, 1); 
        FFT(b, ret, 1);
        for(int i = 0; i <= ret; i++) c[i] = a[i] * b[i];
        FFT(c, ret, -1);
        return ret;
    }
    int main() {
        scanf("%d", &N); N -= 1;
        for(int i = 0; i <= N; i++) scanf("%lf", &a[i].x);
        for(int i = 0; i < N; i++) b[i].x = -1.0 / (double)(N - i) / (double)(N - i);
        for(int i = N + 1; i <= 2 * N; i++) b[i].x = -b[2 * N - i].x;
        Mul(c, a, b, N, 2 * N);
        for(int i = N; i <= N * 2; i++) printf("%.5lf
    ", c[i].x);
        return 0;
    }
    
  • 相关阅读:
    OpenMp之reduction求和
    C++中的字节对齐
    java mail邮件发送(带附件) 支持SSL
    linux下通过命令启动多个终端运行对应的命令和程序
    JAVA数组的定义及用法
    ThreadPoolExecutor使用介绍
    命令拷屏之程序分析
    java实现第五届蓝桥杯供水设施
    java实现第五届蓝桥杯供水设施
    java实现第五届蓝桥杯供水设施
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10023479.html
走看看 - 开发者的网上家园