【BZOJ 2194】 快速傅立叶之二
来源:互联网 发布:旋律合成软件app 编辑:程序博客网 时间:2024/05/21 10:37
思路:
这个题引入了卷积的知识,下面的式子是一种常用的卷积:
形象的理解:
如果
那么就模拟多项式的过程,如果
不难发现,卷积的后两个系数相加,就是现在的答案在
再看这个题:
可是这不是卷积的形式,我们可以先把所有的
为了凑成卷积的形式,我们把
然后就化成了卷积的形式,但是对于一个
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;const int maxn = 100010*3;const double pi = acos(-1);int Bit, rx[maxn];struct Com{ double x, y; Com(double X = 0, double Y = 0){x = X, y = Y;} Com(const Com &t){x = t.x, y = t.y;} Com operator + (const Com &t) const{return Com(x+t.x, y+t.y);} Com operator - (const Com &t) const{return Com(x-t.x, y-t.y);} Com operator * (const Com &t) const{return Com(x*t.x-y*t.y, x*t.y+t.x*y);}};void fft(Com *A, int n, int f){ if(rx[n-1] != n-1) for(int i = 0; i < n; i ++) rx[i] = (rx[i>>1]>>1) | ((i&1)<<(Bit-1)); for(int i = 0; i < n; i ++) if(i < rx[i]) swap(A[i], A[rx[i]]); for(int i = 1; i < n; i <<= 1){ const Com Base(cos(pi/i), f*sin(pi/i)); for(int j = 0; j < n; j += (i<<1)){ Com mi(1, 0); for(int k = 0; k < i; k ++, mi = mi * Base){ Com x = A[j+k], y = A[i+j+k] * mi; A[j+k] = x+y, A[i+j+k] = x-y; } } }}int n, m;Com a[maxn], b[maxn];int main(){ scanf("%d", &n), m = -- n; for(int i = 0; i <= n; i ++) scanf("%lf%lf", &a[n-i].x, &b[i].x); m += n; for(n = 1; n <= m; n <<= 1, Bit ++); fft(a, n, 1), fft(b, n, 1); for(int i = 0; i < n; i ++) a[i] = a[i] * b[i]; fft(a, n, -1); for(int i = m/2; i >= 0; i --) printf("%d\n", int((a[i].x/n)+0.5)); return 0;}
0 0
- 【BZOJ 2194】 快速傅立叶之二
- bzoj 2194: 快速傅立叶之二
- BZOJ 2194(快速傅立叶之二-FFT)
- bzoj 2194快速傅立叶之二
- 【BZOJ 2194】 快速傅立叶之二|FFT
- BZOJ 2194 快速傅立叶之二 FFT
- BZOJ 2194: 快速傅立叶之二
- BZOJ 2194 快速傅立叶之二
- bzoj 2194: 快速傅立叶之二 fft
- BZOJ 2194: 快速傅立叶之二
- 【BZOJ 2194】 快速傅立叶之二
- bzoj 2194 快速傅立叶之二
- BZOJ 2194 快速傅立叶之二
- BZOJ 2194 快速傅立叶之二 快速傅里叶变换
- [BZOJ 2194] 快速傅立叶之二 · FFT
- bzoj 2194: 快速傅立叶之二 (FFT)
- 【bzoj 2194】快速傅立叶之二(FFT)
- 2194: 快速傅立叶之二
- PJMEDIA
- 【Unity技巧】Unity中的优化技术
- SSM(十二) dubbo日志插件
- 一家人
- 剑指offer--包含min函数的栈
- 【BZOJ 2194】 快速傅立叶之二
- 中企故事汇:铁匠之乡借东风出海
- 基于MAVEN的SSM(SPRING,SPRINGMVC,MYBATIS)整合的WEB工程
- 微软编程题-把二元查找树变成排序的双向链表
- nginx安装之后添加SSL站点及常用模块介绍
- 欢迎使用CSDN-markdown编辑器
- mybatis generator只生成insert方法解决方案之一
- 中企故事汇:马可波罗三生三世的故事
- mysql 5.7.18 安装及问题汇总