0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 17:56:28 +00:00

#98. 【模板】多项式乘法

https://sjzezoj.com/submission/65266
This commit is contained in:
Baoshuo Ren 2022-11-27 21:47:09 +08:00
parent d2d46051d3
commit 2d8749d2cf
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
44 changed files with 201 additions and 0 deletions

72
S2OJ/98/98.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const double PI = std::acos(-1);
void FFT(std::vector<std::complex<double>>& a) {
if (a.size() == 1) return;
int m = a.size() >> 1;
std::vector<std::complex<double>> a0, a1;
for (int i = 0; i < m; i++) {
a0.emplace_back(a[i << 1]);
a1.emplace_back(a[i << 1 | 1]);
}
FFT(a0), FFT(a1);
std::complex<double>
w0{std::cos(PI / m), std::sin(PI / m)},
w1{1.0, 0.0};
for (int i = 0; i < m; i++) {
a[i] = a0[i] + w1 * a1[i];
a[i + m] = a0[i] - w1 * a1[i];
w1 *= w0;
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int k = 1 << (std::__lg(n + m) + 1);
std::vector<std::complex<double>> f(k), g(k);
for (int i = 0; i <= n; i++) {
cin >> f[i];
}
for (int i = 0; i <= m; i++) {
cin >> g[i];
}
FFT(f), FFT(g);
for (int i = 0; i < k; i++) {
f[i] *= g[i];
}
FFT(f);
std::reverse(f.begin() + 1, f.end());
for (int i = 0; i <= n + m; i++) {
cout << static_cast<int>(std::round(f[i].real() / k)) << ' ';
}
cout << endl;
return 0;
}

BIN
S2OJ/98/data/data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data11.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data12.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data13.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data14.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data15.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data16.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data17.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data18.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data19.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data20.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/data9.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/ex_data1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/ex_data1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/98/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.