zoukankan      html  css  js  c++  java
  • BZOJ3527 [Zjoi2014]力

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。

    本文作者:ljh2000
    作者博客:http://www.cnblogs.com/ljh2000-jump/
    转载请注明出处,侵权必究,保留最终解释权!

    题目链接:BZOJ3527

     

    正解:FFT

    解题报告:

      FFT模板题,然而我又智障地调了好久…

      把式子中的$q_j$去掉之后发现一个加一个减,上下相加刚好得到$j$,可以分开$FFT$然后组合,也可以直接把整个平移$n$位,最后取后$n$位。

     

    //It is made by ljh2000
    #include <iostream>
    #include <cstdlib>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <algorithm>
    #include <ctime>
    #include <vector>
    #include <queue>
    #include <map>
    #include <set>
    #include <string>
    #include <complex>
    using namespace std;
    typedef long long LL;
    typedef complex<double> C;
    typedef long double LB;
    const double pi = acos(-1);
    const int MAXN = 660011;
    int n,m;
    LB q[MAXN];
    C a[MAXN],b[MAXN];
    
    inline int getint(){
        int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
        if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
    }
    
    inline void fft(C *a,int n,int f){
    	if(n==1) return ;
    	C a0[n>>1],a1[n>>1],wn(cos(2*pi/n),sin(2*pi*f/n)),w(1,0),t;
    	for(int i=0;i<n>>1;i++) a0[i]=a[i<<1],a1[i]=a[i<<1|1];
    	fft(a0,n>>1,f); fft(a1,n>>1,f);
    	for(int i=0;i<n>>1;i++,w*=wn) {
    		t=w*a1[i];
    		a[i]=a0[i]+t;//不用*a1[i]了啊...我在干啥...
    		a[i+(n>>1)]=a0[i]-t;
    	}
    }
    
    inline void work(){
    	n=getint(); for(int i=1;i<=n;i++) scanf("%Lf",&q[i]);
    	for(int i=0;i<n;i++) a[i].real()=q[i+1];/*!!!*/ m=n<<1; int savn=n;
    	for(int i=0;i<n;i++) b[i].real()=-1.0/(n-i)/(n-i),b[2*n-i]=-b[i];//对清楚系数!!!
    	m+=n; for(n=1;n<=m;n<<=1);
    	fft(a,n,1); fft(b,n,1);
    	for(int i=0;i<n;i++) a[i]*=b[i];
    	fft(a,n,-1); m=savn*2;
    	for(int i=savn;i<m;i++) printf("%.3Lf
    ",(LB)a[i].real()/n);//除的数字应该是运算的n!
    }
    
    int main()
    {
        work();
        return 0;
    }
    

      

  • 相关阅读:
    [LeetCode] Permutations II
    [LeetCode] Remove Duplicates from Sorted Array II
    [LeetCode] Permutations
    [LeetCode] Path Sum II
    [LeetCode] Plus One
    [LeetCode] Path Sum
    [LeetCode] Permutation Sequence
    [LeetCode] Pow(x, n)
    [LeetCode] Remove Duplicates from Sorted Array
    [LeetCode] Remove Element
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/6437143.html
Copyright © 2011-2022 走看看