zoukankan      html  css  js  c++  java
  • 【bzoj2194】快速傅立叶之二

     我来水一发FFT模板,这题真没什么好说的。

    #include<iostream>
    #include<cmath>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<ctime>
    #include<iomanip>
    #include<queue>
    #include<algorithm>
    using namespace std;
    #define LL long long
    #define FILE "dealing"
    #define up(i,j,n) for(LL i=(j);i<=n;i++)
    #define pii pair<LL,LL>
    #define mem(i,j) memset(i,j,sizeof(i));
    #define mid ((l+r)>>1)
    #define db double
    void cmax(LL& x,LL y){if(x<y)x=y;}
    void cmin(LL& x,LL y){if(x>y)x=y;}
    LL read(){
    	LL x=0,f=1,ch=getchar();
    	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch-'0');ch=getchar();}
    	return f*x;
    }
    const LL maxn=305000,inf=1000000000;
    struct cp{
    	db x,y;
    	cp(db x=0,db y=0):x(x),y(y){}
    	cp operator+(const cp& b){return cp(x+b.x,y+b.y);}
    	cp operator-(const cp& b){return cp(x-b.x,y-b.y);}
    	cp operator*(const cp& b){return cp(x*b.x-y*b.y,x*b.y+y*b.x);}
    }a[maxn],b[maxn],w[maxn];
    db pi=(acos(-1.0));
    LL H=0,L=1,R[maxn],c[maxn],d[maxn];
    void FFT(cp* a,LL f){
    	for(LL i=0;i<L;i++)if(i<R[i])swap(a[i],a[R[i]]);
    	for(LL len=2;len<=L;len<<=1){
    		LL l=len>>1;
    		cp wn(cos(pi/l),f*sin(pi/l));
    		for(LL i=1;i<l;i++)w[i]=w[i-1]*wn;
    		for(LL st=0;st<L;st+=len)
    			for(LL k=0;k<l;k++){
    				cp x=a[st+k],y=w[k]*a[st+k+l];
    				a[st+k]=x+y,a[st+k+l]=x-y;
    			}
    	}
    	if(f==-1)for(LL i=0;i<L;i++)a[i].x/=L;
    }
    LL n;
    int main(){
    	freopen("dealing.in","r",stdin);
    	freopen("dealing.out","w",stdout);
    	w[0].x=1;
    	n=read();
    	up(i,0,n-1)c[i]=read(),d[i]=read();
    	up(i,0,n-1)a[i].x=c[i],b[i].x=d[n-i-1];
    	for(H=0,L=1;L<n*2;H++)L<<=1;
    	for(LL i=0;i<L;i++)R[i]=(R[i>>1]>>1)|((i&1)<<(H-1));
    	FFT(a,1);FFT(b,1);
    	for(LL i=0;i<L;i++)a[i]=a[i]*b[i];
    	FFT(a,-1);
    	for(LL i=0;i<L;i++)c[i]=(LL)(a[i].x+0.5);
    	up(i,n-1,n*2-2)printf("%lld
    ",c[i]);
    	return 0;
    }
    

      

  • 相关阅读:
    系统综合实践第一次实践作业
    个人作业——软件工程实践总结作业
    个人作业——软件评测
    软件工程实践第五次作业
    Structured Multimodal Attentions for TextVQA
    文字版三国杀开发
    OO Unit 4 Summary
    TextCaps竞赛总结
    Multi-Source Pointer Network
    Pointer Generator Network
  • 原文地址:https://www.cnblogs.com/chadinblog/p/6503044.html
Copyright © 2011-2022 走看看