日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

bzoj2194 快速傅里叶之二

發布時間:2025/7/14 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bzoj2194 快速傅里叶之二 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:對于k = 0 ... n求

解:

首先把i變成從0開始

我們發現a和b的次數(下標)是成正比例的,這不可,于是反轉就行了。

反轉b的話,會發現次數和是n + k,這不可。

反轉a就很吼了。

這個東西恰好是卷積出來的第n - k項的系數。

所以我們把a串反轉,然后用a與b卷積,最后再反轉輸出即可。

1 /************************************************************** 2 Problem: 2194 3 Language: C++ 4 Result: Accepted 5 Time:133643896 ms 6 Memory:14342474884 kb 7 ****************************************************************/ 8 9 #include <cstdio> 10 #include <algorithm> 11 #include <cmath> 12 #include <cstring> 13 14 const int N = 100010; 15 const double pi = 3.1415926535897932384626; 16 17 struct cp { 18 double x, y; 19 cp(double X = 0, double Y = 0) { 20 x = X; 21 y = Y; 22 } 23 inline cp operator +(const cp &w) const { 24 return cp(x + w.x, y + w.y); 25 } 26 inline cp operator -(const cp &w) const { 27 return cp(x - w.x, y - w.y); 28 } 29 inline cp operator *(const cp &w) const { 30 return cp(x * w.x - y * w.y, x * w.y + y * w.x); 31 } 32 }a[N << 2], b[N << 2]; 33 34 int r[N << 2]; 35 36 inline void FFT(int n, cp *a, int f) { 37 for(int i = 0; i < n; i++) { 38 if(i < r[i]) { 39 std::swap(a[i], a[r[i]]); 40 } 41 } 42 43 for(int len = 1; len < n; len <<= 1) { 44 cp Wn(cos(pi / len), f * sin(pi / len)); 45 for(int i = 0; i < n; i += (len << 1)) { 46 cp w(1, 0); 47 for(int j = 0; j < len; j++) { 48 cp t = a[i + len + j] * w; 49 a[i + len + j] = a[i + j] - t; 50 a[i + j] = a[i + j] + t; 51 w = w * Wn; 52 } 53 } 54 } 55 56 if(f == -1) { 57 for(int i = 0; i <= n; i++) { 58 a[i].x /= n; 59 } 60 } 61 return; 62 } 63 64 int main() { 65 int n; 66 scanf("%d", &n); 67 n--; 68 for(int i = 0; i <= n; i++) { 69 scanf("%lf%lf", &a[n - i].x, &b[i].x); 70 } 71 72 int len = 2, lm = 1; 73 while(len <= (n << 1)) { 74 len <<= 1; 75 lm++; 76 } 77 for(int i = 1; i <= len; i++) { 78 r[i] = (r[i >> 1] >> 1) | ((i & 1) << (lm - 1)); 79 } 80 81 FFT(len, a, 1); 82 FFT(len, b, 1); 83 for(int i = 0; i <= len; i++) { 84 a[i] = a[i] * b[i]; 85 } 86 FFT(len, a, -1); 87 88 for(int i = 0; i <= n; i++) { 89 printf("%d\n", (int)(a[n - i].x + 0.5)); 90 } 91 92 return 0; 93 } AC代碼

?

轉載于:https://www.cnblogs.com/huyufeifei/p/10248277.html

總結

以上是生活随笔為你收集整理的bzoj2194 快速傅里叶之二的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。