FFT快速傅里叶变换

#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
typedef complex cp;                     //complex库
const double PI = acos(-1);

void fft(cp *a,int n,int flag)                  //作用:求出a的点值表达,存进a
{
    int i;
    cp a0[n/2+1],a1[n/2+1];

    if(n==1) return;
    cp w_n(cos(2*PI/n),sin(flag*2*PI/n));   //flag=1:求值  flag=2:插值
    cp w(1,0);

    for(i=0; i0 && !ans[i])i--;
        for(; i>=0; i--) printf("%d", ans[i]);
        printf("\n");
    }
    return 0;
}
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const double PI = acos(-1);

struct Complex
{
    double real, image;
    Complex(double real=0.0, double image=0.0): real(real), image(image) {}
    Complex operator +(const Complex &b)
    {
        return Complex(real+b.real,image+b.image);
    }
    Complex operator -(const Complex &b)
    {
        return Complex(real-b.real,image-b.image);
    }
    Complex operator *(const Complex &b)
    {
        return Complex(real*b.real-image*b.image,real*b.image+image*b.real);
    }
};

Complex x[300005]= {0},y[300005]= {0};
char arr1[100005], arr2[100005];
int ans[200005];
int n, m;

void reverse(Complex a[],int n) //对长度为的复数序列a进行DFT和IDFT之前必要的反转变换操作(比特反转),n一定是2的幂次
{
    for(int i=1,j=n/2,k; i=k)
        {
            j-=k;
            k/=2;
        }
        if(j0 && !ans[i])i--;
        for(; i>=0; i--) printf("%d", ans[i]);
        printf("\n");
    }
    return 0;
}

你可能感兴趣的:(FFT快速傅里叶变换)