bzoj2194: 快速傅立叶之二
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=;
const double PI=acos(-);
struct node{
double real,imag;
void clear(){real=imag=;}
node operator +(const node &x){return (node){real+x.real,imag+x.imag};}
node operator -(const node &x){return (node){real-x.real,imag-x.imag};}
node operator *(const node &x){return (node){real*x.real-imag*x.imag,real*x.imag+imag*x.real};}
}a[maxn],b[maxn],c[maxn],t1,t2,w,wn;
int m,n,len,rev[maxn],ans[maxn];
void read(int &x){
x=; int f=; char ch;
for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-;
for (;isdigit(ch);ch=getchar()) x=x*+ch-''; x*=f;
}
int Rev(int x){
int temp=;
for (int i=;i<=len;i++) temp<<=,temp+=(x&),x>>=;
return temp;
}
void FFT(node *a,int op){
for (int i=;i<n;i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int s=;s<=n;s<<=){
wn=(node){cos(*op*PI/s),sin(*op*PI/s)};
for (int i=;i<n;i+=s){
w=(node){,};
for (int j=i;j<i+s/;j++,w=w*wn){
t1=a[j],t2=w*a[j+s/];
a[j]=t1+t2,a[j+s/]=t1-t2;
}
}
}
}
int main(){
read(m); n=,len=;
while (n<(m<<)) n<<=,len++;
for (int i=;i<n;i++) rev[i]=Rev(i);
for (int x,i=;i<m;i++) read(x),a[i].real=x,read(x),b[m--i].real=x;
FFT(a,),FFT(b,);
for (int i=;i<n;i++) c[i]=a[i]*b[i];
FFT(c,-);
for (int i=;i<n;i++) ans[i]=(int)round(c[i].real/n);
for (int i=m-;i<*m-;i++) printf("%d\n",ans[i]);
return ;
}
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2194
题目大意:请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5。 a,b中的元素均为小于等于100的非负整数。
做法:考虑把b数组翻转,Ck的计算就成为了裸的卷积,对于这种题目,翻转是个重要的手段。
bzoj2194: 快速傅立叶之二的更多相关文章
- bzoj2194 快速傅立叶之二 ntt
bzoj2194 快速傅立叶之二 链接 bzoj 思路 对我这种和式不强的人,直接转二维看. 发现对\(C_k\)贡献的数对(i,j),都是右斜对角线. 既然贡献是对角线,我们可以利用对角线的性质了. ...
- [bzoj2194]快速傅立叶之二_FFT
快速傅立叶之二 bzoj-2194 题目大意:给定两个长度为$n$的序列$a$和$b$.求$c$序列,其中:$c_i=\sum\limits_{j=i}^{n-1} a_j\times b_{j-i} ...
- BZOJ2194:快速傅立叶之二(FFT)
Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非 ...
- 2018.11.18 bzoj2194: 快速傅立叶之二(fft)
传送门 模板题. 将bbb序列反过来然后上fftfftfft搞定. 代码: #include<bits/stdc++.h> #define ri register int using na ...
- bzoj千题计划256:bzoj2194: 快速傅立叶之二
http://www.lydsy.com/JudgeOnline/problem.php?id=2194 相乘两项的下标 的 差相同 那么把某一个反过来就是卷积形式 fft优化 #include< ...
- BZOJ2194: 快速傅立叶之二(NTT,卷积)
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1776 Solved: 1055[Submit][Status][Discuss] Descript ...
- BZOJ2194 快速傅立叶之二 【fft】
题目 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. a,b中的元素均为小于等于100的非负整数. 输入格式 ...
- BZOJ2194: 快速傅立叶之二 FFT_卷积
Code: #include <cstdio> #include <algorithm> #include <cmath> #include <cstring ...
- 【BZOJ2194】快速傅立叶之二
[BZOJ2194]快速傅立叶之二 Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k < = i < n ,并且有 n < = 10 ^ 5. ...
随机推荐
- Git 常见的命令操作
克隆 git clone git地址 查看分支 git branch 查看git库状态 git status 切换分支 git che ...
- svn报错:“Previous operation has not finished; run 'cleanup' if it was interrupted“ 的解决方法
今天改完代码提交时,提交接近完成但窗口还未关闭电脑蓝屏了.夏天来了,电脑比人还怕热啊~~~ 心里咯噔一下,估计svn又会出一些莫名其妙的问题了. 果然,待电脑重启后开eclipse,文件还是新增状 ...
- ORA-14450: attempt to access a transactional temp table already in use
在ORACLE数据中修改会话级临时表时,有可能会遇到ORA-14550错误,那么为什么会话级全局临时表会报ORA-14450错误呢,如下所示,我们先从一个小小案例入手: 案例1: SQL> CR ...
- alpha-beta剪枝搜索
•一种基于剪枝( α-βcut-off)的深度优先搜索(depth-first search). •将走棋方定为MAX方,因为它选择着法时总是对其子节点的评估值取极大值,即选择对自己最为有利的着法: ...
- [Java入门笔记] 面向对象三大特征之:封装
了解封装 什么是封装? 在Java的面向对象程序设计中,有三大基本特征:封装.继承和多态.首先我们先来看看封装: 在Java的面对对象程序设计中,封装(Encapsulation)是指一种将函数功能实 ...
- java的输入输出及相关快捷键
首先:导入包import java.util.Scanner; 然后:在主函数中创建对象,eg:Scanner input=new Scanner(System.in); 最后,如果要输入字符串,则 ...
- markdown简要说明源码
##markdown ###什么是markdown: Markdown是一种可以使用普通文本编辑器编写的标记语言,通过简单的标记语法,它可以使普通文本内容具有一定的格式. Markdown具有 ...
- MogileFS系统简单配置实例
实验原理: MogileFS是一个开源的分布式文件系统,用于组建分布式文件集群,由LiveJournal旗下DangaInteractive公司开发,Danga团队开发了包括 Memcached.Mo ...
- Linux下使用 Memory Analyzer
一. 安装Memory Analyzer Tool 打开eclipse >> Help >> Install New Software >> 点击Work With ...
- Sublime Text 技巧
让sublime text2支持中文 安装Sublime Package Control 在Sublime Text 2上用Ctrl+-打开控制台并在里面输入以下代码,Sublime Text 2就会 ...