zoukankan      html  css  js  c++  java
  • [BZOJ 2179] FFT快速傅立叶

    2179: FFT快速傅立叶

    Time Limit: 10 Sec  Memory Limit: 259 MB
    Submit: 4621  Solved: 2498
    [Submit][Status][Discuss]

    Description

    给出两个n位10进制整数x和y,你需要计算x*y。

    Input

    第一行一个正整数n。 第二行描述一个位数为n的正整数x。 第三行描述一个位数为n的正整数y。

    Output

    输出一行,即x*y的结果。

    Sample Input

    1
    3
    4

    Sample Output

    12

    数据范围:
    n<=60000
     
    法法塔模板
    本来在纠结背不住板子
    突然想起来ACM是可以带板子进场的
    嗨森
    #include <bits/stdc++.h>
    using namespace std;
    const int maxn = 262144;
    struct comp{
        double x, y;
        comp(double _x = 0, double _y = 0){
            x = _x;
            y = _y;
        }
        friend comp operator * (const comp &a, const comp &b){
            return comp(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
        }
        friend comp operator + (const comp &a, const comp &b){
            return comp(a.x + b.x, a.y + b.y);
        }
        friend comp operator - (const comp &a, const comp &b){
            return comp(a.x - b.x, a.y - b.y);
        }
    }f[maxn], g[maxn];
    int rev[maxn];
    void dft(comp A[], int len, int kind){
        for(int i = 0; i < len; i++){
            if(i < rev[i]){
                swap(A[i], A[rev[i]]);
            }
        }
        for(int i = 1; i < len; i <<= 1){
            comp wn(cos(acos(-1.0) / i), kind * sin(acos(-1.0) / i));
            for(int j = 0; j < len; j += (i << 1)){
                comp tmp(1, 0);
                for(int k = 0; k < i; k++){
                    comp s = A[j + k], t = tmp * A[i + j + k];
                    A[j + k] = s + t;
                    A[i + j + k] = s - t;
                    tmp = tmp * wn;
                }
            }
        }
        if(kind == -1) for(int i = 0; i < len; i++) A[i].x /= len;
    }
    char a[600000 + 10];
    int ans[maxn] = {0};
    int main(){
        int n, len, L = 0;
        scanf("%d", &n);
        for(len = 1; len < n + n - 1; len <<= 1, L++);
        scanf("%s", a);
        for(int i = 0; i < n; i++) f[i].x = a[n - i - 1] ^ 48;
        scanf("%s", a);
        for(int i = 0; i < n; i++) g[i].x = a[n - i - 1] ^ 48;
        for(int i = 0; i < len; i++){
            rev[i] = rev[i >> 1] >> 1 | (i & 1) << L - 1;
        }
        dft(f, len, 1); dft(g, len, 1);
        for(int i = 0; i < len; i++) f[i] = f[i] * g[i];
        dft(f, len, -1);
        for(int i = 0; i < len; i++)
            ans[i] = (int)(f[i].x + 0.5);
        for(int i = 0; i < len; i++){
            if(ans[i] > 9){
                ans[i + 1] += ans[i] / 10;
                ans[i] %= 10;
            }
        }
        while(!ans[len - 1]) len--;
        for(int i = len - 1; ~i; i--) printf("%d", ans[i]);
        return 0;
    }
  • 相关阅读:
    nginx 点播mp4方法
    NGINX 添加MP4、FLV视频支持模块
    用nginx搭建基于rtmp或者http的flv、mp4流媒体服务器
    obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
    利用nginx搭建RTMP视频点播、直播、HLS服务器
    使用nginx搭建媒体点播服务器
    nginx支持flv MP4 扩展nginx_mod_h264_streaming,nginx-rtmp-module-master,yamdi
    the odb manual
    Zookeeper——启动闪退
    Zookeeper之启动常见错误及解决方法
  • 原文地址:https://www.cnblogs.com/ruoruoruo/p/11756297.html
Copyright © 2011-2022 走看看