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 ...
随机推荐
- mt19937 -- 高质量随机数
优点:产生速度快, 周期大 用法: #include<bits/stdc++.h> using namespace std; int main() { mt19937 mt_rand(ti ...
- 第 8 章 容器网络 - 056 - macvlan 网络结构分析
macvlan 网络结构分析 macvlan 不依赖 Linux bridge,brctl show 可以确认没有创建新的 bridge. 查看一下容器 bbox1 的网络设备: 除了 lo,容器只有 ...
- 【WPF】Silverlight中的Action与Trigger
最近做的Silverlight项目上用到了大量的拖拽,自动跟随等功能,由于赶时间,加上对Silverlight半生不熟,用的是最简单也是最不好维护的方法.项目忙完了闲下来,想重构一下代码,想起了Tri ...
- 使用VueCLI的User Interface Tool(GUI)创建app的图文讲解
(英文原文) 需要安VueCLI3和nodejs. 在terminal输入vue可以看到命令列表: 其中vue ui [options] 就是用于开始和打开vue-cli ui的命令. 使用http: ...
- java开学第一周测试自我感想
开学第一周,王建民老师就对我们进行了java测试,对我们说测试题目是基于期末考试的基础难度来出的.我们的考试完全是靠暑假在家自学的基础,如果在家没有自学java,那完全就是看不懂试卷到底要考什么.由于 ...
- linux动态库
1.编写动态库函数接口 gcc -fPIC -shared -o libfunction.so funtion.c 2.写头文件 3.测试 gcc test.c -L. -lfuntion -o ru ...
- node初学者笔记
helloworld 编辑一个js文件——在该文件所属目录打开命令行cmd——输入'node -v可查看版本——输入'node 00-hellowolrd.js(你的js名字)' 或者直接在文件所属 ...
- pytorch学习记录
1.pytorch中的torch.split只能将tensor分割为相等的几分,如果需要特定的需求将tensor分割开,可以用torch.index_select.使用的时候,先生成index索引,示 ...
- SPL之Iterator和ArrayAccess的结合使用
<?php namespace TabControl; class MyIterator implements \Iterator, \ArrayAccess { private $data = ...
- Leetcode笔记(整理中.......)
1.树的层序遍历 使用两个List 数组 或者 两个queue队列,交替进行,将遍历到的一层放在第一个里面,之后再将遍历到的第二层放在第二个里面. 2.将一个无符号整数的二进制表示形式逆向输出 需要将 ...