zoukankan      html  css  js  c++  java
  • UOJ 34 FFT

    链接:

    http://uoj.ac/problem/34

    代码:

    31 #include <complex>
    32 typedef complex<double> E;
    33 E a[MAXN], b[MAXN];
    34 int n, m;
    35 
    36 namespace FFT {
    37     const double Pi = acos(-1);
    38     int rev[MAXN], L;
    39     void DFT(E *a, int f) {
    40         for (int i = 0; i < n; i++) if (i < rev[i]) swap(a[i], a[rev[i]]);
    41         for (int i = 1; i < n; i <<= 1) {
    42             E wn(cos(Pi / i), f*sin(Pi / i));
    43             for (int p = i << 1, j = 0; j < n; j += p) {
    44                 E w(1, 0);
    45                 for (int k = 0; k < i; k++, w *= wn) {
    46                     E x = a[j + k], y = w*a[j + k + i];
    47                     a[j + k] = x + y; a[j + k + i] = x - y;
    48                 }
    49             }
    50         }
    51         if (f == -1) for (int i = 0; i < n; i++) a[i] /= n;
    52     }
    53     void main() {
    54         m = n + m;
    55         for (n = 1; n <= m; n <<= 1) L++;
    56         for (int i = 0; i < n; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1));
    57         DFT(a, 1); DFT(b, 1);
    58         for (int i = 0; i < n; i++) a[i] = a[i] * b[i];
    59         DFT(a, -1);
    60     }
    61 }
    62 
    63 int main() {
    64     cin >> n >> m;
    65     int x;
    66     rep(i, 0, n + 1) scanf("%d", &x), a[i] = x;
    67     rep(i, 0, m + 1) scanf("%d", &x), b[i] = x;
    68     FFT::main();
    69     rep(i, 0, m + 1) printf("%d ", (int)(a[i].real() + 0.5));
    70     return 0;
    71 }
  • 相关阅读:
    Kafka速览
    分布式消息中间件(二)ActiveMQ
    PageUtil 分页
    Tomcat配置
    CryptographyUtil盐加密
    InitComponent的使用
    Shiro权限总结
    【转】Java自学之路——by马士兵
    ExcelUtil
    Java操作Excel之Poi
  • 原文地址:https://www.cnblogs.com/baocong/p/6876270.html
Copyright © 2011-2022 走看看