BZOJ2179 FFT Fast Fourier

Source: Internet
Author: User

This topic, read the title to know what to do 233

So Konjac Konjac began to learn the FFT ... Then ffting ...

Finally wa3+1ac ...

WA, what's going on?

I'm going to press 4 bits first ... Burst Long long ... Then 3 bits, and a long long T t

So I had to press 2 bits and 233.

1 /**************************************************************2 problem:21793 User:rausen4 language:c++5 result:accepted6 time:616 Ms7 memory:24248 KB8 ****************************************************************/9  Ten#include <cstdio> One#include <cmath> A#include <algorithm> -   - #defineComplex P the using namespacestd; -typedefDoubleLF; -typedefLong Longll; - Const intN =300005; + ConstLF pi = ACOs (-1); -   + structComplex { A lf x, y; at P () {} - P (LF _x, LF _y): X (_x), Y (_y) {} -       -Poperator+ (ConstP &b) { -         returnP (x + b.x, y +b.y); -     } inPoperator- (ConstP &b) { -         returnP (x-b.x, Y-b.y); to     } +Poperator* (ConstP &b) { -         returnP (x * b.x-y * b.y, X * b.y + y *b.x); the     } *} X[n], y[n], w[2][n]; $  Panax Notoginseng intN, K; - ll A[n], b[n]; the   + voidRead (LL *a) { A     intI, now = ceil (LF) n/2) -1; the     CharCH =GetChar (); +      while(Ch <'0'||'9'< ch) ch =GetChar (); -      for(i = n; i;--i) { $(A[now] *=Ten) + = CH-'0'; $CH =GetChar (); -         if(I &1) --Now ; -     } the } -  Wuyi voidPrint (ll *a,intN) { theprintf"%lld", a[n--]); -      for(; ~n;--N) Wuprintf"%02lld", A[n]); - } About   $   - voidFFT (P *x,intKintv) { -     intI, J, L; - P tmp; A      for(i = j =0; I < K; ++i) { +         if(I >j) Swap (X[i], x[j]); the          for(L = k >>1; (J ^= L) < L; L >>=1); -     } $      for(i =2; I <= K; I <<=1) the          for(j =0; J < K; J + =i) the              for(L =0; L < i >>1; ++l) { theTMP = x[j + L + (i >>1)] * w[v][k/i *l]; theX[j + L + (i >>1)] = X[j + L]-tmp; -X[j + L] = x[j + L] +tmp; in             } the } the   About voidWork () { the     inti; the      for(k =1; K < n <<1; K <<=1); the      for(i =0; I <= K; ++i) +w[1][k-i] = w[0][i] = P (cos (pi *2* i/k), sin (pi *2Ik)); -      for(i =0; I < K; ++i) theX[i] = P (A[i],0);BayiFFT (x, K,0); the      for(i =0; I < K; ++i) theY[i] = P (B[i],0); -FFT (Y, K,0); -      for(i =0; I < K; ++i) theX[i] = x[i] *Y[i]; theFFT (x, K,1); the      for(i =0; I <2K ++i) theA[i] = (int) (x[i].x/k +0.5); -      for(i =0; I <2K1; ++i) theA[i +1] + = A[i]/ -, A[i]%= -; the      for(k =2K1;!a[k]; --k); the print (A, k);94 } the   the intMain () { the     inti;98scanf"%d", &n); About Read (a), read (b); -n = ceil (LF) n/2);101 Work ();102     return 0; 103}
View Code

(P.S. Feeling this is a lot simpler and better understood than the Guide = =)

BZOJ2179 FFT Fast Fourier

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.