/*
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. canves图形变换

    canves用得好可以有好多效果: html:<canvas id="myCanvas" width="700" height="300&quo ...

  2. [Windows Server 2012] Tomcat安全加固方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com ★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频. ★ 本节我们将带领大家:Tomca ...

  3. Centos6.7 ELK日志系统部署

    Centos6.7 ELK日志系统部署 原文地址:http://www.cnblogs.com/caoguo/p/4991602.html 一. 环境 elk服务器:192.168.55.134 lo ...

  4. java_randomAccessFile类的使用

    RandomAccessFile java提供的对文件内容的访问,既可以读文件,也可以写文件.RandomAccessFile支持随机访问文件,可以访问文件的任意位置 (1)java文件模型 在硬盘上 ...

  5. 移动端rem布局 js

    // rem布局适配 (function(doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in ...

  6. C# MVC ajax上传 文件

    用普通的ajax提交表单的时候,不能把文件流传到后端去,所以要用到jquery.form.js jquery.form.js到官网下载或者从这里下载:http://pan.baidu.com/s/1c ...

  7. kswapd和pdflush

    首 先,它们存在的目的不同,kswap的作用是管理内存,pdflush的作用是同步内存和磁盘,当然因为数据写入磁盘前可能会换存在内存,这些缓存真正写 入磁盘由三个原因趋势:1.用户要求缓存马上写入磁盘 ...

  8. Serial Fluent UDF on Windows

    test test Table of Contents 1. Serial UDF on Windows OS 1 Serial UDF on Windows OS Note: Udf has to ...

  9. Keil-MDK编译完成后代码大小

    Code 代表执行的代码,程序中所有的函数都位于此处. RO-data 代表只读数据,程序中所定义的全局常量数据和字符串都位于此处. RW-data 代表已初始化的读写数据,程序中定义并且初始化的全局 ...

  10. 【模板】最小生成树Kruskal

    洛谷3366 #include<cstdio> #include<algorithm> using namespace std; ,maxm=; ,ans=; struct e ...