/*
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. SPA设计架构

    1.SPA是采用单页应用(Single Page Application)的方式来开发 2.SPA的框架有如Augular.js.Vue.js等.

  2. jQuery怎么去掉标签的hover效果

    今天项目中遇到jquery去掉hover效果的问题,开始以为直接unbind(“hover”)就可以搞定,可是实际验证这个方法并没有作用,正确的使用方法应该是下面这样: /* 这种方法是新增的,在老的 ...

  3. Spring学习_day03_事务

    本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! Spring_day03 一.事务 1.1 事务 事务 ...

  4. Centos7搭建nginx并提供外网访问

    搭建nginx之后,80端口,其他机器无法访问 查询端口是否开启 firewall-cmd --query-port=80/tcp 永久开放80端口 firewall-cmd --permanent ...

  5. centOS Linux下用yum安装mysql

    centOS Linux下用yum安装mysql      第一篇:安装和配置MySQL   第一步:安装MySQL   [root@192 local]# yum -y install mysql- ...

  6. Git学习总结(标签管理)

    在Git中打标签非常简单,首先,切换到需要打标签的分支上: 然后,敲命令git tag <name>就可以打一个新标签: $ git tag v1. 可以用命令git tag查看所有标签: ...

  7. maven常用dos命令

    在平常的开发中可能会经常切换开发中的一些工具,有时就会对一些常用的命令给忘记了 这里特别记录下来方便以后使用: 1.查看maven版本:mvn -c 2.一件构建启动Tomcat:mvn tomcat ...

  8. Codevs P1017 乘积最大

    P1017 乘积最大 题目描述 Description 今年是国际数学联盟确定的“2000——世界数学年”,又恰逢我国著名数学家华罗庚先生诞辰90周年.在华罗庚先生的家乡江苏金坛,组织了一场别开生面的 ...

  9. PHP面试:说下什么是堆和堆排序?

    堆是什么? 堆是基于树抽象数据类型的一种特殊的数据结构,用于许多算法和数据结构中.一个常见的例子就是优先队列,还有排序算法之一的堆排序.这篇文章我们将讨论堆的属性.不同类型的堆以及堆的常见操作.另外我 ...

  10. 【codeforces 792D】Paths in a Complete Binary Tree

    [题目链接]:http://codeforces.com/contest/792/problem/D [题意] 给你一棵满二叉树; 给你初始节点; 给你若干个往上走,左走,右走操作; 让你输出一系列操 ...