BZOJ2194 Fast Fourier II

Source: Internet
Author: User

And then the title exposes everything.

Read B upside down and it becomes convolution (what is that ...?). can you eat it? ) in the form

So it's just a little bit of an FFT.

1 /**************************************************************2 problem:21943 User:rausen4 language:c++5 result:accepted6 time:2760 Ms7 memory:21900 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cmath> A#include <algorithm> -   - #defineComplex P the using namespacestd; -typedefDoubleLF; - Const intN =300005; - ConstLF pi = ACOs (-1); +   - structComplex { + lf x, y; A P () {} at P (LF _x, LF _y): X (_x), Y (_y) {} -       -Inline Poperator+ (ConstP &x)Const { -         returnP (x + x.x, y +x.y); -     } -Inline Poperator- (ConstP &x)Const { in         returnP (x-x.x, Y-x.y); -     } toInline Poperator* (ConstP &x)Const { +         returnP (x * x.x-y * x.y, X * x.y + y *x.x); -     } the       *Inlinevoid operator+= (ConstP &X) { $* This= * This+X;Panax Notoginseng     } -Inlinevoid operator*= (ConstP &X) { the* This= * This*X; +     } A} X[n], y[n], w[2][n]; the   + intN, Len; - intA[n], b[n]; $   $InlineintRead () { -     intx =0; -     CharCH =GetChar (); the      while(Ch <'0'||'9'<ch) -CH =GetChar ();Wuyi      while('0'<= CH && Ch <='9') { thex = x *Ten+ CH-'0'; -CH =GetChar (); Wu     } -     returnx; About } $   - voidFFT (P *x,intLenintv) { -     intI, J, L; - P tmp; A      for(i = j =0; i < Len; ++i) { +         if(I >j) Swap (X[i], x[j]); the          for(L = Len >>1; (J ^= L) < L; L >>=1); -     } $      for(i =2; I <= Len; I <<=1) the          for(j =0; J < Len; J + =i) the              for(L =0; L < i >>1; ++l) { theTMP = x[j + L + (i >>1)] * w[v][len/i *l]; theX[j + L + (i >>1)] = X[j + L]-tmp; -X[j + L] + =tmp; in             } the } the   About voidWork () { the     inti; the      for(len =1; Len < n <<1; Len <<=1); the      for(i =0; I <= Len; ++i) +w[1][len-i] = w[0][i] = P (cos (pi *2* I/len), sin (pi *2Ilen)); -           the      for(i =0; i < Len; ++i)BayiX[i] = P (A[i],0), y[i] = P (B[i],0); theFFT (x, Len,0), FFT (Y, Len,0); the       -      for(i =0; i < Len; ++i) -X[i] *=Y[i]; theFFT (x, Len,1); the   the      for(i = n-1; i +1< n <<1; ++i) theprintf"%d\n", (int) Round (x[i].x/len)); - } the   the intMain () { the     inti;94n =read (); the      for(i =0; I < n; ++i) theA[i] = Read (), B[n-i-1] =read (); the Work ();98     return 0; About}
View Code

(P.S xs I'm back!!! )

BZOJ2194 Fast Fourier II

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.