FFT

  c[k]=sigma a[i]*b[i-k] 这个形式不好搞……

  而我们熟悉的卷积的形式是这样的 c[k]=sigma a[i]*b[k-i]也就是【下标之和是定值】

  所以我们将a数组反转一下就可以卷积了=。=

 /**************************************************************
Problem: 2194
User: Tunix
Language: C++
Result: Accepted
Time:2008 ms
Memory:48148 kb
****************************************************************/ //BZOJ 2194
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') sign=-; ch=getchar();}
while(isdigit(ch)) {v=v*+ch-''; ch=getchar();}
return v*sign;
}
/*******************template********************/
const int N=;
const double pi=acos(-);
struct comp{
double r,i;
// comp(){}
comp(double _=0.0,double __=0.0) : r(_),i(__){}
comp operator + (const comp &b)const{return comp(r+b.r,i+b.i);}
comp operator - (const comp &b)const{return comp(r-b.r,i-b.i);}
comp operator * (const comp &b)const{return comp(r*b.r-i*b.i,r*b.i+i*b.r);}
}a[N],b[N],c[N];
void FFT(comp *a,int n,int type){
for(int i=,j=;i<n-;++i){
for(int s=n;j^=s>>=,~j&s;);
if(i<j) swap(a[i],a[j]);
}
for(int m=;m<n;m<<=){
double u=pi/m*type; comp wm(cos(u),sin(u));
for(int i=;i<n;i+=(m<<)){
comp w(,);
rep(j,m){
comp &A=a[i+j+m], &B=a[i+j], t=w*A;
A=B-t; B=B+t; w=w*wm;
}
}
}
if (type==-) rep(i,n) a[i].r/=n;
} int main(){
int n=getint();
rep(i,n){
a[n-i-].r=getint();
b[i].r=getint();
}
int len=;
for(len=;len<=n<<;len<<=);
FFT(a,len,); FFT(b,len,);
rep(i,len) c[i]=a[i]*b[i];
FFT(c,len,-);
D(i,n-,) printf("%d\n",int(c[i].r+0.5) );
return ;
}

【BZOJ】【2194】快速傅里叶之二的更多相关文章

  1. BZOJ 2194 快速傅里叶之二

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

  2. BZOJ 2194 快速傅立叶变换之二 | FFT

    BZOJ 2194 快速傅立叶变换之二 题意 给出两个长为\(n\)的数组\(a\)和\(b\),\(c_k = \sum_{i = k}^{n - 1} a[i] * b[i - k]\). 题解 ...

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

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

  4. 【BZOJ 2194】2194: 快速傅立叶之二(FFT)

    2194: 快速傅立叶之二 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1273  Solved: 745 Description 请计算C[k]= ...

  5. bzoj 2194: 快速傅立叶之二 -- FFT

    2194: 快速傅立叶之二 Time Limit: 10 Sec  Memory Limit: 259 MB Description 请计算C[k]=sigma(a[i]*b[i-k]) 其中 k & ...

  6. bzoj 2194 快速傅立叶之二 —— FFT

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2194 如果把 a 序列翻转,则卷积得到的是 c[n-i],再把得到的 c 序列翻转即可. 代 ...

  7. 【BZOJ 2194】快速傅立叶之二

    随便代换一下把它变成多项式乘法,及$C[T]=\sum_{i=0}^{T}A[i]×B[T-i]$这种形式,然后FFT求一下就可以啦 #include<cmath> #include< ...

  8. [BZOJ]2194: 快速傅立叶之二

    题目大意:给定序列a,b,求序列c满足c[k]=sigma(a[i]*b[i-k]) (k<=i<n).(n<=10^5) 思路:观察发现就是普通的卷积反一反(翻转ab其中一个后做卷 ...

  9. 【刷题】BZOJ 2194 快速傅立叶之二

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

随机推荐

  1. UI2_UITextField

    // // ViewController.h // UI2_UITextField // // Created by zhangxueming on 15/7/2. // Copyright (c) ...

  2. 2015年最新出炉的JavaScript开发框架

    前端框架简化了开发过程中,像 Bootstrap 和 Foundation 就是前端框架的佼佼者.在这篇文章了,我们编制了一组新鲜的,实用的,可以帮助您建立高质量的 Web 应用程序的 JavaScr ...

  3. IAR产生可烧录的镜像文件

    Technorati 标签: IAR 烧录镜像 在IAR中,产生能够使用烧录器烧写的hex文件的方法: 1. 只生成可烧写的hex文件:     1.1   在Project Option中的Link ...

  4. (栈)栈 给定push序列,判断给定序列是否是pop序列

    题目: 输入两个整数序列.其中一个序列表示栈的push顺序,判断另一个序列有没有可能是对应的pop顺序.为了简单起见,我们假设push序列的任意两个整数都是不相等的. 比如输入的push序列是1.2. ...

  5. 从源码看java中Integer的缓存问题

    在开始详细的说明问题之前,我们先看一段代码 public static void compare1(){ Integer i1 = 127, i2 = 127, i3 = 128, i4 = 128; ...

  6. GCD Block

    GCD (Grand Central Dispatch) 是Apple公司开发的一种技术,它旨在优化多核环境中的并发操作并取代传统多线程的编程模式. 在Mac OS X 10.6和IOS 4.0之后开 ...

  7. 分享:PHP数组排序总结

    本文内容:PHP二维数组排序,PHP数组排序总结. php数组排序是PHP学习中最基础也是最重要的一部分. 1.常规数组的排序 常规数组是指数组各元素均为字符串或数字,这与这样的数组,我们可以采用so ...

  8. ECSHOP的订单状态在数据库中的表现(order_status, shipping_status, pay_status)

    echop的订单状态都是在ecs_order_info表中的字段里. 订单状态 未确认 取消 确认 已付款 配货中 已发货 已收货 退货 order_status 0 2 1 1 1 5 5 4 sh ...

  9. 为Eclipse设置背景色

    1:打开Eclipse,在菜单栏找到Help—>Install new software.. 2:在打开的Work with中输入: Update Site - http://eclipse-c ...

  10. TDirectory.GetDirectories 获取指定目录下的目录

    使用函数: System.IOUtils.TDirectory.GetDirectories 所有重载: class function GetDirectories(const Path: strin ...