FFT&NTT&多项式相关
2024-08-30 12:37:30
打了FFT
感觉以后多项式不虚了 滑稽
PS
关于详见没写完....
code
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
// pi = 3.14;
inline int read() {
int x = 0,f = 1 ;
char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar() ;}
while(c <= '9' && c >= '0') x = x * 10 + c- '0' ,c = getchar ();
return x *f;
}
const int maxn = 5000007;
const double pi = acos(-1.0);
struct Complex {
double x,y;
Complex (double xx = 0,double yy = 0) { x = xx,y = yy; }
}f[maxn],g[maxn];
Complex operator + (Complex a,Complex b) {return Complex(a.x + b.x,a.y + b.y); }
Complex operator - (Complex a,Complex b) {return Complex(a.x - b.x,a.y - b.y); }
Complex operator * (Complex a,Complex b) {return Complex(a.x * b.x - a.y * b.y,a.x * b.y + a.y * b.x); }
int n,m ;
int l,r[maxn];
int limit = 1;
void FFT (Complex * A,int type) {
for(int i = 0;i < limit;i ++ )
if(i < r[i]) std::swap(A[i],A[r[i]]); //get _迭代序列
for(int mid = 1;mid < limit; mid <<= 1) {
Complex wn (cos(pi / mid) , type * sin(pi / mid));
for(int R = mid << 1 ,j = 0;j < limit ; j += R) {
Complex w(1,0);
for(int k = 0;k < mid;k ++ ,w = w * wn) {
Complex x = A[j + k] , y = w *A[j + mid + k];
A[j + k] = x + y;
A[j + mid + k] = x - y;
}
}
}
}
int main() {
n = read(), m = read();
for(int i = 0;i <= n; ++ i) f[i] = read();
for(int i = 0;i <= m; ++ i) g[i] = read();
while(limit <= n + m) limit <<= 1,l ++;
for(int i = 0;i < limit;i ++)
r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l-1));
FFT(f,1);FFT(g,1);
for(int i = 0;i <= limit;++ i) f[i] = f[i] * g[i];
FFT(f,- 1);
for(int i = 0;i <= n + m;++ i)
printf("%d ",(int) (f[i].x / limit + 0.5));
return 0;
}
最新文章
- SVG动画
- vmware下的centos上网配置
- [POJ3096]Surprising Strings
- css如何实现多行文本时,内容溢出,出现省略号
- CentOs of Tomcat commands
- Linux驱动开发之字符设备模板
- GetPrivateProfileStringA的文件名要小心写
- shell语句记录-awk
- 开源入侵检测系统OSSEC搭建之三:Web界面安装
- angularjs制作的iframe后台管理页切换页面
- CPU使用率计算
- poj1716 Integer Intervals(差分约束)
- 【python】中文的输出,打印,文件编码问题解决方法
- js原生轮播图
- Akka(8): 分布式运算:Remoting-远程查找式
- Java面试题集锦(持续更新)
- impala系列: 字符串函数
- taskService 流程任务组件
- django2.0 路由规则
- Android system :灯光系统_HAL_lights
热门文章
- debounce 与 throttle 区别
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)
- codeforces 1015C
- Linux下部署weblogic应用
- (转)C/S 与 B/S 区别
- 状压dp的题目列表 (一)
- 【洛谷 SP2878】Knights of the Round Table(双联通分量)
- [bzoj3884]上帝与集合的正确用法——欧拉函数
- [Leetcode Week6]Linked List Cycle
- VS mfc MessageBox() 使用英文显示