题目链接

模板题。。

#include<bits/stdc++.h>
using namespace std;
typedef int LL;
typedef double db;
namespace FFT        //使用前需要用 fft_init()函数 初始化
{
    <<;
    .14159265358979323846264338327950288L;
    struct cp
    {
        db a,b;
        cp(,)
        {
            a=a_,b=b_;
        }
        cp operator +(const cp&rhs)const
        {
            return cp(a+rhs.a,b+rhs.b);
        }
        cp operator -(const cp&rhs)const
        {
            return cp(a-rhs.a,b-rhs.b);
        }
        cp operator *(const cp&rhs)const
        {
            return cp(a*rhs.a-b*rhs.b,a*rhs.b+b*rhs.a);
        }
        cp operator !()const
        {
            return cp(a,-b);
        }
    }nw[FFT_MAXN+],f[FFT_MAXN],g[FFT_MAXN],t[FFT_MAXN];    //a<->f,b<->g,t<->c
    int bitrev[FFT_MAXN]; 

    void fft_init()    //初始化 nw[],bitrev[]
    {
        ;<<L)!=FFT_MAXN) L++;
        ;i<FFT_MAXN;i++)  bitrev[i]=bitrev[i>>]>>|((i&)<<(L-));
        ;i<=FFT_MAXN;i++) nw[i]=cp((db)cosl(*pi/FFT_MAXN*i),(db)sinl(*pi/FFT_MAXN*i));
    }

    // n已保证是2的整数次幂
    // flag=1:DFT |  flag=-1: IDFT
    )
    {
        ;<<d)*n!=FFT_MAXN) d++;
        ;i<n;i++) if(i<(bitrev[i]>>d))
            swap(a[i],a[bitrev[i]>>d]);    //    NOTICE!
        ;l<=n;l<<=)
        {
            int del=FFT_MAXN/l*flag;    // 决定 wn是在复平面是顺时针还是逆时针变化,以及变化间距
            ;i<n;i+=l) // ?????????????????
            {
                cp *le=a+i,*ri=a+i+(l>>);    // ?????????????????
                cp *w=flag==? nw:nw+FFT_MAXN;    // 确定wn的起点
                ;k<(l>>);k++)
                {
                    cp ne=*ri * *w;
                    *ri=*le-ne,*le=*le+ne;
                    le++,ri++,w+=del;
                }
            }
        }
        ) ;i<n;i++) a[i].a/=n,a[i].b/=n;
    }

    // convo(a,n,b,m,c) a[0..n]*b[0..m] -> c[0..n+m]
    void convo(LL *a,int n,LL *b,int m,LL *c)
    {//if(n<=100 && m<=100 || min(n,m)<=5)    标程用了直接暴力的方式,或许可以更快
        ;;    // N+1是c扩展后的长度
        ;i<N;i++)    // 扩展 a[],b[] ,存入f[],g[] ,以0填充新空间
        {
            f[i]=cp((db)(i<=n? a[i]:),);
            g[i]=cp((db)(i<=m? b[i]:),);
        }
        dft(f,N),dft(g,N);
        ;i<N;i++)    // 频域求积
            t[i]=f[i]*g[i];
        dft(t,N,-);
        ;i<=n+m;i++) c[i]=LL(t[i].a+0.5);
    }
}

<<|],s2[<<|],s3[<<|];
LL a[<<|],b[<<|],c[<<|];

int main()
{
    FFT::fft_init();
    while(~scanf("%s%s",s1,s2))
    {
        memset(s3,,sizeof(s3));
        ,m=strlen(s2)-;
        ;i<=n;i++)    a[i]=s1[i]-';
        ;i<=m;i++)    b[i]=s2[i]-';
        FFT::convo(a,n,b,m,c);
        c[n+m+]=;
        ;i<n+m-i;i++) swap(c[i],c[n+m-i]);
        ;i<=n+m;i++)
        {
            c[i+]+=c[i]/;
            c[i]%=;
        }
        ;
        &&len>) len--;
        ;i--) s3[len-i]=c[i]+';
        s3[len+]=;
        puts(s3);
    }
}

51nod 1028 大数乘法 V2 【FFT模板题】的更多相关文章

  1. 1028 大数乘法 V2(FFT or py)

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B ...

  2. FFT/NTT [51Nod 1028] 大数乘法 V2

    题目链接:51Nod 传送门 没压位,效率会低一点 1.FFT #include <cstdio> #include <cstring> #include <algori ...

  3. 51Nod 1028 大数乘法 V2

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 分析: FFT/NTT板子题... 代码: NTT板子: #inc ...

  4. 51 Nod 1028 大数乘法 V2【Java大数乱搞】

    1028 大数乘法 V2 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 给出2个大整数A,B,计算A*B的结果. Input 第1行:大数A 第2行:大数B (A ...

  5. UOJ 34: 多项式乘法(FFT模板题)

    关于FFT 这个博客的讲解超级棒 http://blog.miskcoo.com/2015/04/polynomial-multiplication-and-fast-fourier-transfor ...

  6. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  7. HDU 1402 A * B Problem Plus (FFT模板题)

    FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...

  8. ACM学习历程—51NOD1028 大数乘法V2(FFT)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1028 题目大意就是求两个大数的乘法. 但是用普通的大数乘法,这 ...

  9. 51NOD 1027 大数乘法

    1027 大数乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题   给出2个大整数A,B,计算A*B的结果.   Input 第1行:大数A 第2行:大数B (A,B ...

随机推荐

  1. 从数据库、页面加载速度角度思考 id设计 sku asin

    (已对数据进行字符串替换,去身份识别.隐私跟踪) 12-13-14-15-16-18岁20女孩夏装初中高中学生韩版上衣服短袖T恤衫-tmall.com天猫 https://detail.tmall.c ...

  2. The MEAN stack is a modern replacement for the LAMP (Linux, Apache, MySQL, PHP/Python) stack

    w https://www.mongodb.com/blog/post/building-your-first-application-mongodb-creating-rest-api-using- ...

  3. (转) intellij idea部署web项目时的位置(Tomcat)

    这篇文章说的比较好: 原文地址:https://blog.csdn.net/zmx729618/article/details/78340566 1.当你项目启动的时候console能看到项目运行的位 ...

  4. Ora01653 :是表空间不足

    解决方案:表空间中增加数据文件: ALTER TABLESPACE 表空间名称ADD DATAFILE 'D:\app\Administrator\oradata\orcl\Ibomis1.dbf' ...

  5. Python笔记(二十七)_魔法方法_容器

    定制容器 容器类型的协议: 定制不可变容器,只需要定义__len__()和__getitem__()方法 定制可变容器,需要定义__len__().__getitem__().__setitem__( ...

  6. JS使用 popstate 事件监听物理返回键

    pushHistory();        window.addEventListener("popstate", function (e) {            if (or ...

  7. Js基本类型中常用的方法总结

    1.数组 push() -----> 向数组末尾添加新的数组项,参数为要添加的项,返回值是新数组的长度,原数组改变: pop() -----> 删除数组末尾的最后一项,参数无,返回值是删除 ...

  8. 代码执行testng的几种方式

    一.指定test class Test class FirstTest package cas.eric; import org.testng.annotations.Optional; import ...

  9. STL hash function的模板特化

    哈希函数的作用是将一个值映射为一个哈希值,从而根据这个哈希值,在哈希表中对数据进行定位. template <class _Val, class _Key, class _HashFcn, cl ...

  10. python 安装成windows服务

    参考文档 https://blog.csdn.net/kongxx/article/details/65435076 https://www.cnblogs.com/lishuai0214/artic ...