BZOJ 2194 fast Fourier-Fast Fourier Transformation

Source: Internet
Author: User

BZOJ 2194 fast Fourier-Fast Fourier Transformation

Given two sequences a and B with a length of n, evaluate c [k] = Σ a [I] * B [I-k].

This is not a convolution form, so we reverse the B array, followed by the convolution form.

Then♂Happy ground FFT

 

#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include #define M 263000#define PI 3.1415926535897932384626433832795028841971using namespace std;struct Complex{double a,b;Complex() {}Complex(double _,double __):a(_),b(__) {}Complex operator + (const Complex &x) const{return Complex(a+x.a,b+x.b);}Complex operator - (const Complex &x) const{return Complex(a-x.a,b-x.b);}Complex operator * (const Complex &x) const{return Complex(a*x.a-b*x.b,a*x.b+b*x.a);}void operator *= (const Complex &x){*this=(*this)*x;}}a[M],b[M],p[M];int n;void FFT(Complex x[],int n,int type){static Complex temp[M];if(n==1) return ;int i;for(i=0;i
     
      >1]=x[i],temp[i+n>>1]=x[i+1];memcpy(x,temp,sizeof(Complex)*n);Complex *l=x,*r=x+(n>>1);FFT(l,n>>1,type);FFT(r,n>>1,type);Complex root(cos(type*2*PI/n),sin(type*2*PI/n)),w(1,0);for(i=0;i
      
       >1;i++,w*=root)temp[i]=l[i]+w*r[i],temp[i+(n>>1)]=l[i]-w*r[i];memcpy(x,temp,sizeof(Complex)*n);}int main(){int i,digit;cin>>n;for(i=0;i
       
        

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.