打了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;
}

最新文章

  1. SVG动画
  2. vmware下的centos上网配置
  3. [POJ3096]Surprising Strings
  4. css如何实现多行文本时,内容溢出,出现省略号
  5. CentOs of Tomcat commands
  6. Linux驱动开发之字符设备模板
  7. GetPrivateProfileStringA的文件名要小心写
  8. shell语句记录-awk
  9. 开源入侵检测系统OSSEC搭建之三:Web界面安装
  10. angularjs制作的iframe后台管理页切换页面
  11. CPU使用率计算
  12. poj1716 Integer Intervals(差分约束)
  13. 【python】中文的输出,打印,文件编码问题解决方法
  14. js原生轮播图
  15. Akka(8): 分布式运算:Remoting-远程查找式
  16. Java面试题集锦(持续更新)
  17. impala系列: 字符串函数
  18. taskService 流程任务组件
  19. django2.0 路由规则
  20. Android system :灯光系统_HAL_lights

热门文章

  1. debounce 与 throttle 区别
  2. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)
  3. codeforces 1015C
  4. Linux下部署weblogic应用
  5. (转)C/S 与 B/S 区别
  6. 状压dp的题目列表 (一)
  7. 【洛谷 SP2878】Knights of the Round Table(双联通分量)
  8. [bzoj3884]上帝与集合的正确用法——欧拉函数
  9. [Leetcode Week6]Linked List Cycle
  10. VS mfc MessageBox() 使用英文显示