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 ...
随机推荐
- CentOS7.6 如何设置静态ip
[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/[root@localhost network-scripts] ...
- 关于select的默认样式问题
select { border: solid 1px #000; appearance:none; -moz-appearance:none; -webkit-appearance:none; pad ...
- bootstrap的渲染机制
bootstrap的渲染机制. http://www.cnblogs.com/djtao/p/5942620.html 源码解析: http://www.cnblogs.com/ahole/p/588 ...
- (转)c# 断言类
Assert 类 使用 true/false 命题验证单元测试中的条件. 继承层次结构 System.Object Microsoft.VisualStudio.TestTools.UnitTesti ...
- (25)线程---local数据隔离
线程之间本身是数据共享的,当多个线程同时修改一份数据的时候,数据就可能不 准确,特别是线程量特别大的时候,为了保证数据准确性: (1) 通过线程锁Lock (2)通过local数据隔离 from th ...
- 并发之ThreadLocal
ThreadLocal ThreadLocal 用一种存储变量与线程绑定的方式,在每个线程中用自己的 ThreadLocalMap 安全隔离变量,为解决多线程程序的并发问题提供了一种新的思路. 简 ...
- ADO.NET介绍2
一.Connection对象 Connection对象也称为数据库连接对象,Connection对象的功能是负责对数据源的连接.所有Connection对象的基类都是DbConnection类. Co ...
- Bulk RNA-Seq转录组学习
与之对应的是single cell RNA-Seq,后面也会有类似文章. 参考:https://github.com/xuzhougeng/Learn-Bioinformatics/ 作业:RNA-s ...
- WPF打印涉及到的关键类
DocumentViewer--->FixedDocument----> PageContent ---->FixedPage
- 2.7 UML状态图
问题的引出 顺序图是对对象的动态行为进行建模,有多个对象的参与.协作 问题: 当需要考察单个实体的动态行为时, 用UML如何来建模呢? 什么是单个实体:一个软件系统?一个子系统?一个模块.一个构件? ...