/*
Welcome Hacking
Wish You High Rating
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<complex>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=(xx<<)+(xx<<)+ch-'';ch=getchar();}
return xx*ff;
}
const int maxn=(<<)+;
const double PI=acos(-1.0);
typedef complex<double> C;
int N,M,L,R[maxn];
C a[maxn],b[maxn];
void FFT(C a[],int arg){
for(int i=;i<N;i++)
if(i<R[i])
swap(a[i],a[R[i]]);
for(int i=;i<N;i<<=){
C wn(cos(PI/i),arg*sin(PI/i));
for(int p=i<<,j=;j<N;j+=p){
C w(,);
for(int k=;k<i;k++,w*=wn){
C x=a[j+k],y=w*a[j+k+i];
a[j+k]=x+y,a[j+k+i]=x-y;
}
}
}
}
int main(){
//freopen("in","r",stdin);
N=read(),M=read();
for(int i=;i<=N;i++)
a[i]=read();
for(int i=;i<=M;i++)
b[i]=read();
M+=N;
for(N=;N<=M;N<<=)
L++;
for(int i=;i<N;i++)
R[i]=(R[i>>]>>)|((i&)<<(L-));
FFT(a,);FFT(b,);
for(int i=;i<=N;i++)
a[i]*=b[i];
FFT(a,-);
for(int i=;i<=M;i++)
printf("%d ",(int)(a[i].real()/N+0.5));
return ;
}

FFT还有蝶形数组那部分不懂,emmmm,先这样吧,抄一个黄学长的模板,体验acmer用模板切题的快感。

hdu1402

A * B Problem Plus

Problem Description
Calculate A * B.
 
Input
Each line will contain two integers A and B. Process to end of file.

Note: the length of each integer will not exceed 50000.

 
Output
For each case, output A * B in one line.
 
Sample Input
1
2
1000
2
 
Sample Output
2
2000
 
Author
DOOM III
 
 
直接上模板改一改,注意清除前导0和进位(错了一次,逃)
 /*
Welcome Hacking
Wish You High Rating
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<complex>
using namespace std;
int read(){
int xx=,ff=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')ff=-;ch=getchar();}
while(ch>=''&&ch<=''){xx=(xx<<)+(xx<<)+ch-'';ch=getchar();}
return xx*ff;
}
const int maxn=(<<)+;
const double PI=acos(-1.0);
typedef complex<double> C;
int N,M,L,R[maxn];
C a[maxn],b[maxn];
void FFT(C a[],int arg){
for(int i=;i<N;i++)
if(i<R[i])
swap(a[i],a[R[i]]);
for(int i=;i<N;i<<=){
C wn(cos(PI/i),arg*sin(PI/i));
for(int p=i<<,j=;j<N;j+=p){
C w(,);
for(int k=;k<i;k++,w*=wn){
C x=a[j+k],y=w*a[j+k+i];
a[j+k]=x+y,a[j+k+i]=x-y;
}
}
}
}
char s1[],s2[];
int ans[];
int main(){
//freopen("in","r",stdin);
/*N=read(),M=read();
for(int i=0;i<=N;i++)
a[i]=read();
for(int i=0;i<=M;i++)
b[i]=read();*/
while(scanf("%s",s1)!=EOF){
scanf("%s",s2);
N=strlen(s1)-,M=strlen(s2)-;
for(int i=;i<=N;i++)
a[i]=s1[N-i]-'';
for(int i=;i<=M;i++)
b[i]=s2[M-i]-'';
M+=N;
for(N=;N<=M;N<<=)
L++;
for(int i=;i<N;i++)
R[i]=(R[i>>]>>)|((i&)<<(L-));
FFT(a,);FFT(b,);
for(int i=;i<=N;i++)
a[i]*=b[i];
FFT(a,-);
for(int i=M;i>=;i--)
ans[i]=(int)(a[i].real()/N+0.5);
int k;
for(k=;k<=M||ans[k];k++)
if(ans[k]>=)
ans[k+]+=ans[k]/,ans[k]%=;
while(!ans[k]&&k>)
k--;
for(int i=k;i>=;i--)
printf("%d",ans[i]);
puts("");
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(R,,sizeof(R));
memset(ans,,sizeof(ans));
L=;
}
return ;
}
 
 
 
 
 
 

FFT模板——copied from hzwer的更多相关文章

  1. 再写FFT模板

    没什么好说的,今天又考了FFT(虽然不用FFT也能过)但是确实有忘了怎么写FFT了,于是乎只有重新写一遍FFT模板练一下手了.第一部分普通FFT,第二部分数论FFT,记一下模数2^23*7*17+1 ...

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

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

  3. FFT模板(多项式乘法)

    FFT模板(多项式乘法) 标签: FFT 扯淡 一晚上都用来捣鼓这个东西了...... 这里贴一位神犇的博客,我认为讲的比较清楚了.(刚好适合我这种复数都没学的) http://blog.csdn.n ...

  4. hdu1402(大数a*b&fft模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 给出两个长度1e5以内的大数a, b, 输出 a * b. 思路: fft模板 详情参 ...

  5. P1919 【模板】A*B Problem升级版 /// FFT模板

    题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...

  6. fft模板 HDU 1402

    // fft模板 HDU 1402 #include <iostream> #include <cstdio> #include <cstdlib> #includ ...

  7. [hdu1402]大数乘法(FFT模板)

    题意:大数乘法 思路:FFT模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...

  8. UOJ#34 FFT模板题

    写完上一道题才意识到自己没有在博客里丢过FFT的模板-- 这道题就是裸的多项式乘法,可以FFT,可以NTT,也可以用Karasuba(好像有人这么写没有T),也可以各种其他分治乘法乱搞-- 所以我就直 ...

  9. 【bzoj2179】FFT快速傅立叶 FFT模板

    2016-06-01  09:34:54 很久很久很久以前写的了... 今天又比较了一下效率,貌似手写复数要快很多. 贴一下模板: #include<iostream> #include& ...

随机推荐

  1. JS高级——扩展内置对象的方法

    基本概念 内置对象有很多,几个比较重要的:Math.String.Date.Array 基本使用 1.内置对象创建出来的对象使用的方法使用的其实都是内置对象的原型对象中的方法 (1)a并没有charA ...

  2. Android Studio 快捷键整理

    Alt+回车 导入包,自动修正 Ctrl+N   查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L  格式化代码Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如ge ...

  3. Codeforces_738B

    B. Spotlights time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. C# null

    var t0est = Convert.ToString(""+null);//结果"" var t1est = ("" + null).T ...

  5. dos命令在vba中应用

    正常情况下想要遍历文件夹和子文件夹,可以采用递归的方式 Sub ListFilesTest() With Application.FileDialog(msoFileDialogFolderPicke ...

  6. day12-闭包函数、装饰器

    目录 闭包函数 装饰器 无参装饰器 有参装饰器 装饰器模板 闭包函数 之前我们都是通过参数将外部的值传给函数,而闭包打破了层级关系,把局部变量拿到全局使用,并把外部的变量封装到内部函数中,然后下次直接 ...

  7. ThinkPHP框架表单验证AJAX

    验证有两种方式:静态验证与动态验证. 一.静态验证 在模型类里面预先定义好该模型的自动验证规则,我们称为静态定义. 验证时要在test表的Model里面加验证条件:新建testModel.class. ...

  8. [ZJOJ] 5794 2018.08.10【2018提高组】模拟A组&省选 旅行

    Description 悠悠岁月,不知不觉,距那传说中的pppfish晋级泡泡帝已是过 去数十年.数十年 中,这颗泡泡树上,也是再度变得精彩,各种泡泡 天才辈出,惊艳世人,然而,似乎 不论后人如何的出 ...

  9. Map的两种遍历方式

    ********************************************************************************* ****************** ...

  10. Flask - app的配置和实例化Flask的参数

    目录 Flask - app的配置和实例化Flask的参数 app的配置 app的配置 Flask - app的配置和实例化Flask的参数 app的配置 基本用法: from flask impor ...