"BZOJ2179" FFT fast fourier high accuracy multiply template problem

Source: Internet
Author: User

Advertising:
#include <stdio.h>int main(){    puts("转载请注明出处[vmurder]谢谢");    puts("网址:blog.csdn.net/vmurder/article/details/44015679");}
Exercises

In fact, no matter, just put a template + understanding comments

Code:
#include <cmath>#include <cstdio>#include <cstring>#include <complex>#include <iostream>#include <algorithm>using namespace STD;#define N 131075intN,c[n];Complex<Double> A[n],b[n],p[n];Const DoublePi=ACOs(-1);voidFFT (Complex<Double> x[],intNintType) {intI,j,k,t;/* Press bits to flip: for example 01234567 04261537 000 000 001 100 010 010 011 110 100 00 1 101 101 011 111 111 * *     for(i=0, t=0; i<n;i++)//Bitwise ROLLOVER{if(i>t) Swap (x[i],x[t]); for(j=n>>1;(t^=j) <j;j>>=1); }//For WN    //type== 1 O'Clock forward rotation unit angle on complex plane    //Type==-1 negative rotation unit angle on complex plane     for(k=2; k<=n;k<<=1)     {Complex<Double> Wn (Cos(type*2*pi/k),Sin(type*2*pi/k)); for(i=0; i<n;i+=k) {Complex<Double> W (1,0), T;//You can write W = 1 directly, the x axis is the real part, and the Y axis is the imaginary part.              for(j=0;j<k>>1; w*=wn,j++) t=w*x[i+j+ (k>>1)], x[i+j+ (k>>1)]=x[i+j]-t, x[i+j]+=t; }    }}intMain () {intI,j,k;Cin>>n; for(GetChar (), i=n-1; i>=0; i--) A[i]=getchar ()-' 0 '; for(GetChar (), i=n-1; i>=0; i--) B[i]=getchar ()-' 0 '; for(j=n,i=1;i>>2<j;i<<=1) N=i; FFT (A,n,1), FFT (B,n,1);//Convert past     for(i=0; i<n;i++) P[i]=a[i]*b[i]; FFT (p,n,-1);//Convert back    intlen=0;//Output     for(i=0; i<n;i++) c[i]=p[i].real ()/n+0.1;//eps=0.1     for(i=0; i<n;i++)if(C[i]) len=i, c[i+1]+=c[i]/Ten, c[i]%=Ten; for(i=len;i>=0; i--)printf("%d", C[i]);return 0;}

"BZOJ2179" FFT fast Fourier high-precision multiply template problem

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.