UOJ #34 多项式乘法 FFT快速傅立叶变换
来源:互联网 发布:大华ipc onvif协议端口 编辑:程序博客网 时间:2024/06/06 01:58
题目大意:这是一道模板题。
CODE:
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 1000010using namespace std;const double PI = acos(-1.0);struct Complex{double x,y;Complex(double _,double __ = .0):x(_),y(__) {}Complex() {}void operator +=(const Complex &a) {x += a.x,y += a.y;}void operator -=(const Complex &a) {x -= a.x,y -= a.y;}void operator /=(double a) {x /= a,y /= a;}void operator *=(const Complex &a) {double _ = x * a.x - y * a.y,__ = x * a.y + y * a.x;x = _,y = __;}Complex operator +(const Complex &a)const {return Complex(x + a.x,y + a.y);}Complex operator -(const Complex &a)const {return Complex(x - a.x,y - a.y);}Complex operator /(double a)const {return Complex(x / a,y / a);}Complex operator *(const Complex &a)const {return Complex(x * a.x - y * a.y,x * a.y + y * a.x);}};inline void FFT(Complex A[],int cnt,int flag) {for(int i = 0,k = 0; i < cnt; ++i) {if(i < k)swap(A[i],A[k]);for(int j = cnt >> 1; (k ^= j) < j; j >>= 1);}int i,j;Complex w,wn,t;for(int k = 2; k <= cnt; k <<= 1)for(wn = Complex(cos(2 * PI / k),flag * sin(2 * PI / k)),i = 0; i < cnt; i += k)for(w = 1.0,j = 0; j < k >> 1; ++j,w *= wn) {t = w * A[i + j + (k >> 1)];A[i + j + (k >> 1)] = A[i + j] - t;A[i + j] += t;}if(!~flag)for(int i = 0; i < cnt; ++i)A[i] /= cnt;}int l1,l2;Complex A[MAX],B[MAX];int main(){cin >> l1 >> l2;for(int i = 0; i <= l1; ++i)scanf("%lf",&A[i].x);for(int i = 0; i <= l2; ++i)scanf("%lf",&B[i].x);int l = l1 + l2,cnt;for(cnt = 1; cnt <= l; cnt <<= 1);FFT(A,cnt,1),FFT(B,cnt,1);for(int i = 0; i < cnt; ++i)A[i] *= B[i];FFT(A,cnt,-1);for(int i = 0; i <= l1 + l2; ++i)printf("%d%c",int(A[i].x + .5)," \n"[i == l1 + l2]);return 0;}
0 0
- UOJ #34 多项式乘法 FFT快速傅立叶变换
- [UOJ34]多项式乘法(快速傅立叶变换FFT)
- [UOJ 34]多项式乘法(FFT)
- 【FFT优化】[UOJ#34]多项式乘法
- 【UOJ#34】 多项式乘法(FFT && NTT)
- [FFT 模板题] UOJ #34 多项式乘法
- [UOJ#34]多项式乘法(FFT)
- [uoj 34 多项式乘法] FFT&NTT 模板
- uoj 34 多项式乘法(fft入门)
- UOJ 34 多项式乘法(FFT)
- [UOJ#34]多项式乘法(FFT)
- [uoj 34 多项式乘法] FFT&NTT 模板
- [挖坑][uoj]多项式乘法 FFT
- 【FFT-快速傅立叶变换】
- 快速傅立叶变换FFT
- [codevs3123]大整数乘法(快速傅立叶变换FFT)
- 【快速傅里叶变换】[UOJ#34]多项式乘法
- [省选前题目整理][UOJ 34]多项式乘法(FFT)
- nginx--IP白名单
- discuz论坛通过程序插入帖子
- 使用libcurl实现的下载器
- POJ 3461 Oulipo (KMP模板题)
- C++ STL简介
- UOJ #34 多项式乘法 FFT快速傅立叶变换
- Windows Gather User Credentials (phishing)
- SQL基础(廿二)---UNION ALL
- HTTP协议缓存策略深入详解之etag妙用
- javafX8初探(滑块)
- [每天一个知识点]26-软件工程-有多少管理是为了满足管理者的掌控感
- Restore openstack after ip address changed
- 线程的两种实现方式
- H5页面点击按钮时的loading图