无编辑摘要 |
无编辑摘要 |
||
| 第28行: | 第28行: | ||
{| class="mw-collapsible mw-collapsed wikitable" | {| class="mw-collapsible mw-collapsed wikitable" | ||
|- | |- | ||
! colspan=3 | 前方检测到核聚变打击,请谨慎打开! | ! colspan=3 | FFT 前方检测到核聚变打击,请谨慎打开! | ||
|- | |- | ||
| | | <code> | ||
#include <iostream> | |||
#include <cstring> | |||
#include <algorithm> | |||
#include <cmath> | |||
using namespace std; | |||
const int N = 300000; | |||
const double PI = acos(-1); | |||
struct Complex | |||
{ | |||
double x, y; | |||
Complex operator+ (const Complex& t) const | |||
{ | |||
return {x + t.x, y + t.y}; | |||
} | |||
Complex operator- (const Complex& t) const | |||
{ | |||
return {x - t.x, y - t.y}; | |||
} | |||
Complex operator* (const Complex& t) const | |||
{ | |||
return {x * t.x - y * t.y, x * t.y + y * t.x}; | |||
} | |||
}a[N], b[N]; | |||
char s1[N], s2[N]; | |||
int res[N]; | |||
int rev[N], bit, tot; | |||
void fft(Complex a[], int inv) | |||
{ | |||
for (int i = 0; i < tot; i ++ ) | |||
if (i < rev[i]) | |||
swap(a[i], a[rev[i]]); | |||
for (int mid = 1; mid < tot; mid *= 2) | |||
{ | |||
auto w1 = Complex({cos(PI / mid), inv * sin(PI / mid)}); | |||
for (int i = 0; i < tot; i += mid * 2) | |||
{ | |||
auto wk = Complex({1, 0}); | |||
for (int j = 0; j < mid; j ++, wk = wk * w1) | |||
{ | |||
auto x = a[i + j], y = wk * a[i + j + mid]; | |||
a[i + j] = x + y, a[i + j + mid] = x - y; | |||
} | |||
} | |||
} | |||
} | |||
int main() | |||
{ | |||
scanf("%s%s", s1, s2); | |||
int n = strlen(s1) - 1, m = strlen(s2) - 1; | |||
for (int i = 0; i <= n; i ++ ) a[i].x = s1[n - i] - '0'; | |||
for (int i = 0; i <= m; i ++ ) b[i].x = s2[m - i] - '0'; | |||
while ((1 << bit) < n + m + 1) bit ++ ; | |||
tot = 1 << bit; | |||
for (int i = 0; i < tot; i ++ ) | |||
rev[i] = ((rev[i >> 1] >> 1)) | ((i & 1) << (bit - 1)); | |||
fft(a, 1), fft(b, 1); | |||
for (int i = 0; i < tot; i ++ ) a[i] = a[i] * b[i]; | |||
fft(a, -1); | |||
int k = 0; | |||
for (int i = 0, t = 0; i < tot || t; i ++ ) | |||
{ | |||
t += a[i].x / tot + 0.5; | |||
res[k ++ ] = t % 10; | |||
t /= 10; | |||
} | |||
while (k > 1 && !res[k - 1]) k -- ; | |||
for (int i = k - 1; i >= 0; i -- ) printf("%d", res[i]); | |||
return 0; | |||
} </code> | |||
|} | |} | ||
[[category:玩家]] | [[category:玩家]] | ||
2022年8月23日 (二) 23:31的版本
这里是慕斯sama!(一直想改名为musesama,但是因为hermit的名称已经在各大论坛上了索性就用这个了)
会点中式建筑,有点红石技艺,浅尝辄止pvp,正在被带领学习中世纪建筑(
不善交际的美少女一枚捏(大概
- 出没地点:
各大群聊
- 记不住的东西:
算法知识点:#include
| FFT 前方检测到核聚变打击,请谨慎打开! | ||
|---|---|---|
| ||