分析:网上别家的代码都分析的很好,我只是给我自己贴个代码,我是kuangbin的搬运工

一点想法:其实FFT就是快速求卷积罢了,当小数据的时候我们完全可以用母函数来做,比如那种硬币问题

FFT只是用来解决数据规模较大时的办法,可以达到nlogn的效率,大体原理就是运用了n次单位复根的折半引理

具体可以看算法导论

高度仰慕kuangbin大神的模板,实在是不想自己写

对于这个题,我们10^k的系数看成多项式系数,然后求卷积,进位就好了

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=2e5+;
const double pi = acos(-1.0);
struct complex{
double r,i;
complex(double R=,double I=){
r=R;i=I;
}
complex operator+(const complex &a)const{
return complex(r+a.r,i+a.i);
}
complex operator-(const complex &a)const{
return complex(r-a.r,i-a.i);
}
complex operator*(const complex &a)const{
return complex(r*a.r-i*a.i,r*a.i+i*a.r);
}
};
void change(complex x[],int len){
int i,j,k;
for(i=,j=len/;i<len-;++i){
if(i<j)swap(x[i],x[j]);
k=len/;
while(j>=k){j-=k;k>>=;}
if(j<k)j+=k;
}
}
void fft(complex x[],int len,int on){
change(x,len);
for(int i=;i<=len;i<<=){
complex wn(cos(-on**pi/i),sin(-on**pi/i));
for(int j=;j<len;j+=i){
complex w(,);
for(int k=j;k<j+i/;++k){
complex u = x[k];
complex t = w*x[k+i/];
x[k]=u+t;
x[k+i/]=u-t;
w=w*wn;
}
}
}
if(on==-)for(int i=;i<len;++i)x[i].r/=len;
}
complex x1[N],x2[N];
char str1[N/],str2[N/];
int sum[N];
int main(){
while(~scanf("%s%s",str1,str2)){
int len1 = strlen(str1);
int len2 = strlen(str2),len=;
while(len<len1*||len<len2*)len<<=;
for(int i=;i<len1;++i)
x1[i]=complex(str1[len1--i]-'',);
for(int i=len1;i<len;++i)
x1[i]=complex(,);
for(int i=;i<len2;++i)
x2[i]=complex(str2[len2--i]-'',);
for(int i=len2;i<len;++i)
x2[i]=complex(,);
fft(x1,len,);
fft(x2,len,);
for(int i=;i<len;++i)
x1[i]=x1[i]*x2[i];
fft(x1,len,-);
for(int i=;i<len;++i)
sum[i]=(int)(x1[i].r+0.5);
for(int i=;i<len;++i){
sum[i+]+=sum[i]/;
sum[i]%=;
}
len = len1+len2-;
while(sum[len]<=&&len>)--len;
for(int i=len;i>=;--i)printf("%d",sum[i]);
printf("\n");
}
return ;
}

HDU1402 A * B Problem Plus FFT的更多相关文章

  1. HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本 ...

  2. [hdu1402]A * B Problem Plus(FFT模板题)

    解题关键:快速傅里叶变换fft练习. 关于结果多项式长度的确定,首先将短多项式扩展为长多项式,然后扩展为两倍. #include<cstdio> #include<cstring&g ...

  3. hdu 1402 A * B Problem Plus FFT

    /* hdu 1402 A * B Problem Plus FFT 这是我的第二道FFT的题 第一题是完全照着别人的代码敲出来的,也不明白是什么意思 这个代码是在前一题的基础上改的 做完这个题,我才 ...

  4. 【CF954I】Yet Another String Matching Problem(FFT)

    [CF954I]Yet Another String Matching Problem(FFT) 题面 给定两个字符串\(S,T\) 求\(S\)所有长度为\(|T|\)的子串与\(T\)的距离 两个 ...

  5. FFT/NTT模板 既 HDU1402 A * B Problem Plus

    @(学习笔记)[FFT, NTT] Problem Description Calculate A * B. Input Each line will contain two integers A a ...

  6. hdu----(1402)A * B Problem Plus(FFT模板)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU1402 A * B Problem Plus(FFT)

    http://acm.hdu.edu.cn/showproblem.php?pid=1402 初学FFT. http://www.cnblogs.com/WABoss/p/FFT_Note.html ...

  8. 【FFT】hdu1402 A * B Problem Plus

    FFT板子. 将大整数看作多项式,它们的乘积即多项式的乘积在x=10处的取值. #include<cstdio> #include<cmath> #include<cst ...

  9. A * B Problem Plus(fft)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 hdu_1402:A * B Problem Plus Time Limit: 2000/100 ...

随机推荐

  1. 简单易懂的现代魔法——Play Framework攻略1

    哇哈哈,寒假结束啦,于是我又开新坑了....这次的主角可是大名鼎鼎的Play Framework!!那么闲话少说,开始攻略吧! 1.什么是Play Framework? 大名鼎鼎的play frame ...

  2. 使用ajax()方法加载服务器数据

    使用ajax()方法加载服务器数据 使用ajax()方法是最底层.功能最强大的请求服务器数据的方法,它不仅可以获取服务器返回的数据,还能向服务器发送请求并传递数值,它的调用格式如下: jQuery.a ...

  3. [Unity菜鸟] 产生各不相同的随机数

    1. 网上很多方法都说用时间种子来解决,但是在极短的时间内,这种方法没效 Random r = new Random(DateTime.Now.Millisecond); Random Counter ...

  4. 对象的类型转换P109

    类作为一种应用数据类型,和基本数据类型的变量一样.不同类中存在对象与对象之间的类型转问题,对象的类型转换只能在  具有继承关系的 父类对象-----子类对象 之间进行   子类通常比父类拥有更多的域和 ...

  5. seafile安装日志(非教程)

    需要的软件: python 2.7.x(从 Seafile 5.1 开始,python 版本最低要求为2.7) python-setuptools python-imaging python-mysq ...

  6. Csharp日常笔记

    1. 1.退出程序                   this.Close();             //方法退关闭当前窗口. Application.Exit();       //方法退出整 ...

  7. jQuery选择器最佳实践--来自jQ官网

    1.基于ID选择器进行查询,并且使用find方法. //快速 $("#container div.footer"); //超快 $("#container"). ...

  8. android rabbitMQ

    http://www.cnblogs.com/wufawei/archive/2012/03/31/2427823.html http://www.raywenderlich.com/5527/get ...

  9. Android的底层库libutils介绍

    第一部分 libutils概述 libutils是Android的底层库,这个库以C++实现,它提供的API也是C++的.Android的层次的C语言程序和库,大都基于libutils开发. libu ...

  10. cdev_init函数

    linux-2.6.22/include/linux/cdev.hstruct cdev {   struct kobject kobj;          // 每个 cdev 都是一个 kobje ...