hdu1402 傅里叶变换

模板题,直接套FFT。


ACcode:

#include
#include
#include
#include
#include
#include
#include
using namespace std;

int ans[NS];
char s1[NS],s2[NS];

const int NS=1<<18;
const double pi=acos(-1.0);
struct Complex{
    double x,y;
    Complex() {}
    Complex(double xa,double xb):x(xa),y(xb) {}
    Complex operator + (const Complex mul)const{
        return Complex(x+mul.x,y+mul.y);
    }
    Complex operator - (const Complex mul)const{
        return Complex(x-mul.x,y-mul.y);
    }
    Complex operator * (const Complex mul)const{
        return Complex(x*mul.x-y*mul.y,x*mul.y+y*mul.x);
    }
    double real(){ return x; }
}A[NS],B[NS],P[NS];

void build(Complex _P[],Complex P[],int n,int m,int pos,int &cnt)
{
    if (m==n) {
        _P[cnt++]=P[pos];
    } else {
        build(_P,P,n,m<<1,pos,cnt);
        build(_P,P,n,m<<1,pos+m,cnt);
    }
}

inline int binary(int x)
{
    for (int i=1;;i<<=1)
    if (i>=x) return i<<1;
}

void FFT(Complex P[],int &n,double oper)
{
    int cnt=0;
    static Complex _P[NS];
    build(_P,P,n,1,0,cnt);
    copy(_P,_P+n,P);

    for (int d=1;d=0;i--)
        A[len1-i-1]=Complex(s1[i]-'0',0);
    for (int i=len2-1;i>=0;i--)
        B[len2-i-1]=Complex(s2[i]-'0',0);
    for (int i=len1;i0 ; i--);
        for(;i>=0;i--) printf("%d",ans[i]);
        puts("");
    }
    return 0;
}


你可能感兴趣的:(数学)