FFT模板(无讲解)
#include<bits/stdc++.h>
using namespace std;
const int maxn=1E6+;
const double pi=3.1415926535898;
int n,m,limit,r[maxn*],len;
struct com
{
double a,b;
com(double A=,double B=){a=A,b=B;}
void operator=(com x){a=x.a,b=x.b;}
com operator+(com x){return com(a+x.a,b+x.b);}
com operator-(com x){return com(a-x.a,b-x.b);}
com operator*(com x){return com(a*x.a-b*x.b,a*x.b+b*x.a);}
}f[maxn*],g[maxn*];
int re(int x)
{
int sum=;
for(int i=;i<len;++i)sum=sum*+((x&(<<i))>);
return sum;
}
void FFT(com*A,int g)
{
for(int i=;i<limit;++i)
if(i<r[i])swap(A[i],A[r[i]]);
for(int i=;i<=limit;i*=)
{
com w(cos(*pi/i),g*sin(*pi/i));
for(int j=;j<limit/i;++j)
{
com d(,);
for(int k=;k<i/;++k)
{
com a=A[i*j+k],b=d*A[i*j+i/+k];
A[i*j+k]=a+b;
A[i*j+i/+k]=a-b;
d=d*w;
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<=n;++i)cin>>f[i].a;
for(int i=;i<=m;++i)cin>>g[i].a;
limit=;
len=;
while(limit<=n+m+)
{
limit*=;
++len;
}
for(int i=;i<limit;++i)r[i]=re(i);
FFT(f,);
FFT(g,);
for(int i=;i<=limit;++i)f[i]=f[i]*g[i];
FFT(f,-);
for(int i=;i<=n+m;++i)cout<<int(f[i].a/limit+0.5)<<' ';
cout<<endl;
return ;
}
FFT模板(无讲解)的更多相关文章
- P1919 【模板】A*B Problem升级版 /// FFT模板
题目大意: 给定l,输入两个位数为l的数A B 输出两者的乘积 FFT讲解 这个讲解蛮好的 就是讲解里面贴的模板是错误的 struct cpx { double x,y; cpx(double _x= ...
- 再写FFT模板
没什么好说的,今天又考了FFT(虽然不用FFT也能过)但是确实有忘了怎么写FFT了,于是乎只有重新写一遍FFT模板练一下手了.第一部分普通FFT,第二部分数论FFT,记一下模数2^23*7*17+1 ...
- HDU 1402 A * B Problem Plus (FFT模板题)
FFT模板题,求A*B. 用次FFT模板需要注意的是,N应为2的幂次,不然二进制平摊反转置换会出现死循环. 取出结果值时注意精度,要加上eps才能A. #include <cstdio> ...
- FFT模板(多项式乘法)
FFT模板(多项式乘法) 标签: FFT 扯淡 一晚上都用来捣鼓这个东西了...... 这里贴一位神犇的博客,我认为讲的比较清楚了.(刚好适合我这种复数都没学的) http://blog.csdn.n ...
- hdu1402(大数a*b&fft模板)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1402 题意: 给出两个长度1e5以内的大数a, b, 输出 a * b. 思路: fft模板 详情参 ...
- fft模板 HDU 1402
// fft模板 HDU 1402 #include <iostream> #include <cstdio> #include <cstdlib> #includ ...
- [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 ...
- NTT模板(无讲解)
#include<bits/stdc++.h>//只是在虚数部分改了一下 using namespace std; typedef long long int ll; ; ; ; ; ll ...
- LCT模板(无讲解)
怎么说呢,照着打一遍就自然理解了,再打一遍就会背了,再打一遍就会推了. // luogu-judger-enable-o2 #include<bits/stdc++.h> using na ...
随机推荐
- PySpark笔记
spark源码位置:https://github.com/apache/spark Spark Core核心RDD及编程 什么是RDD:1.是一个抽象类不能直接使用,在子类中实现抽象方法是一个抽象类不 ...
- zlib 2.1.8 编译遇到的问题以及解决方法
环境:win7 x64 + vs2013 1.用vs2013打开zlib-1.2.8\contrib\vstudio\vc11\zlibvc.sln进行编译 包含了下面的的多个项目: miniunz: ...
- Codeforces 801C - Voltage Keepsake
C. Voltage Keepsake 题目链接:http://codeforces.com/problemset/problem/801/C time limit per test 2 second ...
- css特效博客
1. 前端网上: e344657992 http://www.qdfuns.com/notes/15477/02cb463c28d9fe69ee0bc804448b8316.html
- thinkphp5中如何使用 usort
thinkphp5中如何使用 usort 一.总结 一句话总结:其实比较函数加上命名空间就好啦,不然找不到 比较函数加命名空间 数组做usort的第二个参数 usort($question_list, ...
- JS中如何生成全局变量
JS中如何生成全局变量 一.总结 一句话总结:在函数内部,一般用var声明的为局部变量,没用var声明的一般为全局变量 在函数内没用var声明的一般为全局变量 1.js中的函数中的this指向的是谁? ...
- 通过wifi 连接 adb 到 手机
网上很多文章都需要先用 usb 线连接先做一下设置,然后才能通过下面的方法连接 julian@julian-ThinkPad-T450:~/tools/android_sdk/platform-too ...
- HeadFirst Ruby 第七章总结 references
前言 这一章的内容关于 references,讲了当 Ruby 程序中可能会遇到关于 reference 与 object 之间概念混淆而导致的问题. 导言 本章从一个 astronomer 发现 s ...
- gcc -02引起内存溢出'unsigned i'应修订为'volatile unsigned i'
2017-12-13 10:44:19gcc -02引起内存溢出'unsigned i'应修订为'volatile unsigned i' 1.3.100 driver/char/random.cst ...
- Misha and Palindrome Degree CodeForces - 501E (回文串计数)
大意: 给定字符串, 求多少个区间重排后能使原串为回文串. 先特判掉特殊情况, 对于两侧已经相等的位置之间可以任意组合, 并且区间两端点至少有一个在两侧相等的位置处, 对左右两种情况分别求出即可. # ...