• 「ZJOI2014」力 FFT


    FFTl裸题,小于的部分直接做,大于的部分倒序后再做就行了。

    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN = 1 << 18;
    const double Pi = acos(-1.0);
    struct cp {
        double x, y;
        cp() { x = y = 0; }
        cp(double x, double y) : x(x), y(y) {}
        inline cp operator+(const cp &o) const { return cp(x + o.x, y + o.y); }
        inline cp operator-(const cp &o) const { return cp(x - o.x, y - o.y); }
        inline cp operator*(const cp &o) const { return cp(x * o.x - y * o.y, x * o.y + o.x * y); }
    } f[MAXN], g[MAXN], b[MAXN];
    int rev[MAXN];
    inline void DFT(cp *arr, int len, int flg) {
        for (int i = 0; i < len; ++i)
            if (i < rev[i])
                swap(arr[i], arr[rev[i]]);
        for (int i = 2; i <= len; i <<= 1) {
            cp wn = cp(cos(2 * Pi / i), flg * sin(2 * Pi / i));
            for (int j = 0; j < len; j += i) {
                cp w = cp(1, 0);
                for (int k = j; k < j + i / 2; ++k, w = w * wn) {
                    cp x = arr[k], y = arr[k + i / 2] * w;
                    arr[k] = x + y;
                    arr[k + i / 2] = x - y;
                }
            }
        }
        if (flg == -1)
            for (int i = 0; i < len; ++i) arr[i].x /= len;
    }
    int n;
    int main() {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) scanf("%lf", &f[i].x), g[n - i + 1].x = f[i].x, b[i].x = 1.0 / i / i;
        int len = 1;
        while (len <= (n << 1)) len <<= 1;
        for (int i = 0; i < len; ++i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (len >> 1));
        DFT(f, len, 1), DFT(g, len, 1), DFT(b, len, 1);
        for (int i = 0; i < len; ++i) f[i] = f[i] * b[i], g[i] = g[i] * b[i];
        DFT(f, len, -1), DFT(g, len, -1);
        for (int i = 1; i <= n; ++i) printf("%.3f
    ", f[i].x - g[n - i + 1].x);
    }
    
  • 相关阅读:
    http简单demo
    启迪思维:循环链表
    数据表行列转换
    防止短时间内重复提交表单数据js约束
    ASP.NET2.0文件上传以及图片处理
    支付宝倒计时代码
    js 定时刷新页面
    C# 将cookiecontainer写到本地
    用C#生成随机中文汉字验证码的基本原理
    删除指定文件夹里的所有文件
  • 原文地址:https://www.cnblogs.com/Orz-IE/p/12039269.html
Copyright © 2020-2023  润新知