题意:对于k = 0 ... n求

解:

首先把i变成从0开始

我们发现a和b的次数(下标)是成正比例的,这不可,于是反转就行了。

反转b的话,会发现次数和是n + k,这不可。

反转a就很吼了。

这个东西恰好是卷积出来的第n - k项的系数。

所以我们把a串反转,然后用a与b卷积,最后再反转输出即可。

 /**************************************************************
Problem: 2194
Language: C++
Result: Accepted
Time:133643896 ms
Memory:14342474884 kb
****************************************************************/ #include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring> const int N = ;
const double pi = 3.1415926535897932384626; struct cp {
double x, y;
cp(double X = , double Y = ) {
x = X;
y = Y;
}
inline cp operator +(const cp &w) const {
return cp(x + w.x, y + w.y);
}
inline cp operator -(const cp &w) const {
return cp(x - w.x, y - w.y);
}
inline cp operator *(const cp &w) const {
return cp(x * w.x - y * w.y, x * w.y + y * w.x);
}
}a[N << ], b[N << ]; int r[N << ]; inline void FFT(int n, cp *a, int f) {
for(int i = ; i < n; i++) {
if(i < r[i]) {
std::swap(a[i], a[r[i]]);
}
} for(int len = ; len < n; len <<= ) {
cp Wn(cos(pi / len), f * sin(pi / len));
for(int i = ; i < n; i += (len << )) {
cp w(, );
for(int j = ; j < len; j++) {
cp t = a[i + len + j] * w;
a[i + len + j] = a[i + j] - t;
a[i + j] = a[i + j] + t;
w = w * Wn;
}
}
} if(f == -) {
for(int i = ; i <= n; i++) {
a[i].x /= n;
}
}
return;
} int main() {
int n;
scanf("%d", &n);
n--;
for(int i = ; i <= n; i++) {
scanf("%lf%lf", &a[n - i].x, &b[i].x);
} int len = , lm = ;
while(len <= (n << )) {
len <<= ;
lm++;
}
for(int i = ; i <= len; i++) {
r[i] = (r[i >> ] >> ) | ((i & ) << (lm - ));
} FFT(len, a, );
FFT(len, b, );
for(int i = ; i <= len; i++) {
a[i] = a[i] * b[i];
}
FFT(len, a, -); for(int i = ; i <= n; i++) {
printf("%d\n", (int)(a[n - i].x + 0.5));
} return ;
}

AC代码

bzoj2194 快速傅里叶之二的更多相关文章

  1. 【BZOJ-2179&2194】FFT快速傅里叶&快速傅里叶之二 FFT

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2978  Solved: 1523[Submit][Status][Di ...

  2. 【BZOJ】【2194】快速傅里叶之二

    FFT c[k]=sigma a[i]*b[i-k] 这个形式不好搞…… 而我们熟悉的卷积的形式是这样的 c[k]=sigma a[i]*b[k-i]也就是[下标之和是定值] 所以我们将a数组反转一下 ...

  3. BZOJ 2194 快速傅里叶之二

    fft. #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> ...

  4. bzoj2194 快速傅立叶之二 ntt

    bzoj2194 快速傅立叶之二 链接 bzoj 思路 对我这种和式不强的人,直接转二维看. 发现对\(C_k\)贡献的数对(i,j),都是右斜对角线. 既然贡献是对角线,我们可以利用对角线的性质了. ...

  5. 【BZOJ2194】快速傅立叶之二

    [BZOJ2194]快速傅立叶之二 Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. ...

  6. [bzoj2194]快速傅立叶之二_FFT

    快速傅立叶之二 bzoj-2194 题目大意:给定两个长度为$n$的序列$a$和$b$.求$c$序列,其中:$c_i=\sum\limits_{j=i}^{n-1} a_j\times b_{j-i} ...

  7. BZOJ2194:快速傅立叶之二(FFT)

    Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...

  8. bzoj2194: 快速傅立叶之二

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  9. 2018.11.18 bzoj2194: 快速傅立叶之二(fft)

    传送门 模板题. 将bbb序列反过来然后上fftfftfft搞定. 代码: #include<bits/stdc++.h> #define ri register int using na ...

随机推荐

  1. Bootstrap 字体图标(Glyphicons)

    http://www.runoob.com/bootstrap/bootstrap-glyphicons.html 什么是字体图标? 字体图标是在 Web 项目中使用的图标字体.虽然,Glyphico ...

  2. C# Note1:深入浅出WPF-MVVM篇

    一.资源说明 (1)配套视频:深入浅出WPF  讲的不错! 待更!

  3. Java 线程的生命周期

    当线程被创建并启动以后,它既不是一启动就进入了执行状态,也不是一直处于执行状态,在线程的生命周期中,它要经过新建(New).就绪(Runnable).运行(Running).阻塞(Blocked)和死 ...

  4. 读懂掌握 Python logging 模块源码 (附带一些 example)

    搜了一下自己的 Blog 一直缺乏一篇 Python logging 模块的深度使用的文章.其实这个模块非常常用,也有非常多的滥用.所以看看源码来详细记录一篇属于 logging 模块的文章. 整个 ...

  5. spring 启动脚本分析

    参考:JVM 参数使用总结 参考:java  -Xms -Xmx -XX:PermSize -XX:MaxPermSize 参考:JVM调优总结 -Xms -Xmx -Xmn -Xss 参考:JAVA ...

  6. Python OpenCV人脸识别案例

    ■环境 Python 3.6.0 Pycharm 2017.1.3 ■库.库的版本 OpenCV 3.4.1 (cp36) ■haarcascades下载 https://github.com/ope ...

  7. delphi中退出是弹出让你确定的几种确定对话框怎么写?

    procedure TForm2.btn1Click(Sender: TObject); begin if MessageBox(Handle, '你确定要退出系统吗?', '信息提示', MB_OK ...

  8. Scss - 简单笔记

    原文链接:scss 教程 手头上疯狂在用 scss,虽然可以在里面写原生的 css, 但是为了保持风格的一致性,还是滚去看了看 scss 文档. 一.变量 变量的引入是 scss 的一个核心特性,变量 ...

  9. hibernate主配置文件中指定session与当前线程绑定

    配置一条属性 <property name="hibernate.current_session_context_class">thread</property& ...

  10. zabbix在ubuntu16.04上的安装

    开始安装 zabbix具体安装可以参考官方文档写的很详细,令人高兴的是现在有了中文的版本的翻译,这里简要说下. 上篇文章我写了在ubuntu14.04上安装zabbix,见这里http://www.c ...