/*
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. dubbo之延迟连接及粘滞链接接

    延迟连接 延迟连接用于减少长连接数.当有调用发起时,再创建长连接.1 <dubbo:protocol name="dubbo" lazy="true" / ...

  2. HDU_1698_Just a Hook_线段树区间更新

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. java静态变量、实例变量和局部变

    实例变量又称成员变量: 1⃣️成员变量定义在类中,在整个类中都可以被访问 2⃣️成员变量随着对象的建立而建立,随对象的消失而消失,存在于对象所在的对内存中 3⃣️成员变量有默认初始值 局部变量: 1⃣ ...

  4. uva 1586 Molar mass(Uva-1586)

    这题做的相当的复杂...之前做的现在应该能简单一点了写的. 我的代码: #include <bits/stdc++.h> using namespace std; main() { int ...

  5. cin输入过慢用scanf???现在才知道cin可以加速

    今天才发现可以加速原帖 只需要两行放在main开头即可 ios_base::sync_with_stdio(0); cin.tie(NULL);

  6. Linux常用shell命令持续总结

    1. 查看端口运行 netstat -lnp|grep 80 2. 定时任务 Crontab -e 编辑任务 Crontab -l 查看当前任务列表 /var/log/cron-* 任务日志

  7. 51.percentiles rank以及网站访问时延SLA统计

    主要知识点: percentile_ranks的用法 percentile的优化     一.percentile_ranks的用法 SLA:就是所提供的服务的标准. 比如一个网站的提供的访问延时的S ...

  8. Python OS & sys模块

    os模块(* * * *) os模块是与操作系统交互的一个接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname" ...

  9. (ccf)201709-4 通信网络

    #include<iostream> #include<memory.h> #include<stack> #include<string> #incl ...

  10. PAT 1047. Student List for Course

    Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...