【BZOJ 2194】快速傅立叶之二
随便代换一下把它变成多项式乘法,及$C[T]=\sum_{i=0}^{T}A[i]×B[T-i]$这种形式,然后FFT求一下就可以啦
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define read(x) x=getint()
using namespace std;
const int N = 400003;
const double Pi = acos(- 1.0);
int getint() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
}
struct cp {
double r, i;
cp (double _r = 0.0, double _i = 0.0) : r(_r), i(_i) {}
cp operator + (const cp &x) {return cp(r + x.r, i + x.i);}
cp operator - (const cp &x) {return cp(r - x.r, i - x.i);}
cp operator * (const cp &x) {return cp(r * x.r - i * x.i, r * x.i + i * x.r);}
};
cp A[N], u, t;
int rev[N];
void DFT(cp *a, int n, int flag) {
for(int i = 0; i < n; ++i) A[rev[i]] = a[i];
for(int i = 0; i < n; ++i) a[i] = A[i];
for(int m = 2; m <= n; m <<= 1) {
cp wn(cos(2.0 * Pi / m * flag), sin(2.0 * Pi / m * flag));
int mid = m >> 1;
for(int i = 0; i < n; i += m) {
cp w(1.0);
for(int j = 0; j < mid; ++j) {
u = a[i + j], t = a[i + j + mid] * w;
a[i + j] = u + t;
a[i + j + mid] = u - t;
w = w * wn;
}
}
}
if (flag == -1)
for(int i = 0; i < n; ++i)
a[i].r /= n;
}
void init(int &n) {
int k = 1, ret, L = 0;
for(; k < n; k <<= 1, ++L);
n = k;
for(int i = 0; i < n; ++i) {
k = i; ret = 0;
for(int j = 0; j < L; ++j)
ret <<= 1, ret |= k & 1, k >>= 1;
rev[i] = ret;
}
}
void FFT(int *a, int *b, int *c, int la, int lb) {
static cp x[N], y[N];
int len = la + lb - 1;
init(len);
for(int i = 0; i < len; ++i)
x[i].r = a[i], x[i].i = 0;
for(int i = 0; i < len; ++i)
y[i].r = b[i], y[i].i = 0;
DFT(x, len, 1); DFT(y, len, 1);
for(int i = 0; i < len; ++i)
x[i] = x[i] * y[i];
DFT(x, len, -1);
for(int i = 0; i < len; ++i)
c[i] = (int) (x[i].r + 0.5);
}
int x[N], y[N], a[N], n;
int main() {
read(n);
for(int i = 0; i < n; ++i)
read(x[i]), read(y[i]);
for(int i = 0; i < n; ++i)
a[i] = x[n - i - 1];
FFT(y, a, x, n, n);
for(int i = 0; i < n; ++i)
a[i] = x[n - i - 1];
for(int i = 0; i < n; ++i)
printf("%d\n", a[i]);
return 0;
}
233
【BZOJ 2194】快速傅立叶之二的更多相关文章
- bzoj 2194: 快速傅立叶之二 -- FFT
2194: 快速傅立叶之二 Time Limit: 10 Sec Memory Limit: 259 MB Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k & ...
- bzoj 2194 快速傅立叶之二 —— FFT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2194 如果把 a 序列翻转,则卷积得到的是 c[n-i],再把得到的 c 序列翻转即可. 代 ...
- [BZOJ]2194: 快速傅立叶之二
题目大意:给定序列a,b,求序列c满足c[k]=sigma(a[i]*b[i-k]) (k<=i<n).(n<=10^5) 思路:观察发现就是普通的卷积反一反(翻转ab其中一个后做卷 ...
- 【刷题】BZOJ 2194 快速傅立叶之二
Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...
- BZOJ.2194.快速傅立叶之二(FFT 卷积)
题目链接 \(Descripiton\) 给定\(A[\ ],B[\ ]\),求\[C[k]=\sum_{i=k}^{n-1}A[i]*B[i-k]\ (0\leq k<n)\] \(Solut ...
- BZOJ 2194 快速傅立叶之二 ——FFT
[题目分析] 咦,这不是卷积裸题. 敲敲敲,结果样例也没过. 看看看,卧槽i和k怎么反了. 艹艹艹,把B数组取个反. 靠靠靠,怎么全是零. 算算算,最终的取值范围算错了. 交交交,总算是A掉了. [代 ...
- bzoj 2194: 快速傅立叶之二【NTT】
看别的blog好像我用了比较麻烦的方法-- (以下的n都--过 \[ c[i]=\sum_{j=i}^{n}a[i]*b[j-i] \] 设j=i+j \[ c[i]=\sum_{j=0}^{n-i} ...
- BZOJ 2194 快速傅立叶变换之二 | FFT
BZOJ 2194 快速傅立叶变换之二 题意 给出两个长为\(n\)的数组\(a\)和\(b\),\(c_k = \sum_{i = k}^{n - 1} a[i] * b[i - k]\). 题解 ...
- 【BZOJ 2194】2194: 快速傅立叶之二(FFT)
2194: 快速傅立叶之二 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1273 Solved: 745 Description 请计算C[k]= ...
- 【BZOJ】2194: 快速傅立叶之二
http://www.lydsy.com/JudgeOnline/problem.php?id=2194 题意:求$c[k]=\sum_{k<=i<n} a[i]b[i-k], n< ...
随机推荐
- C#读写app.config中的数据
C#读写app.config中的数据 读语句: String str = ConfigurationManager.AppSettings["DemoKey"]; 写语句: Con ...
- C# 格式化小总结
C#中几个常用的格式化标识符 C或c Currency 货币格式 D或d Decimal 十进制格式(十进制整数,不要和.Net的Decimal数据类型混淆了) E或e Exponent 指数格式 F ...
- Google Play笔记之上架
我最近负责Google Play上架的主要工作 ,现已进入开放测试阶段(随后就可全球首发~~).接入工作已完成,这篇记录一下上架后期的笔记. 开放测试 开放测试是指对所有玩家进行开放式测试,玩家可以通 ...
- 全息眼镜HoloLens可快速捕捉真人3D图像
http://www.d9soft.com/zixun/62287.html 北京时间3月28日午间消息,微软研发部门开发出一种新的3D视频捕捉系统“Holoportation”,可以实现将某人3D图 ...
- [No000002]大学本科文凭贬值了多少?
<大学本科文凭贬值了多少?> 朋友开网络公司,招应届毕业生.他们是小本经营,人手本就不多,面试的时候,忙不过来就会拉我过去,假装是公司的面试官.主管什么的,算是滥竽充数.我装模作样面试了几 ...
- 转: windows 10使用原生linux bash命令行
转: https://www.zybuluo.com/pandait/note/337430 windows 10使用原生linux bash命令行 linux bash windows-10 第一时 ...
- ORACLE临时表总结(转载)
转载地址:http://www.cnblogs.com/kerrycode/p/3285936.html 临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类 ...
- NOI2018准备Day3
noip2016成绩出来了,199,268名 noip2017需要考过6个女生才能进省队,不包括明年会突然跳出来的大神...... 今天晚上玩了一晚上,做了2道题. 这事儿只干今晚一次
- http://kb.cnblogs.com/zt/ef/
http://kb.cnblogs.com/zt/ef/ http://blog.csdn.net/mackz/article/details/8605063 http://www.telerik.c ...
- vbs http
get请求 模拟发送http请求到百度Dim httpSet http = CreateObject("Msxml2.ServerXMLHTTP")http.open " ...