bzoj 3527 [Zjoi2014]力

这题网上题解我觉得比较好的是这个

 这题的本质与OI没太大关系,主要考察多项式的变化能力。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iomanip>
#include<queue>
#include<algorithm>
using namespace std;
#define LL long long
#define FILE "dealing"
#define up(i,j,n) for(LL i=(j);i<=n;i++)
#define pii pair<LL,LL>
#define mem(i,j) memset(i,j,sizeof(i));
#define mid ((l+r)>>1)
#define db double
void cmax(LL& x,LL y){if(x<y)x=y;}
void cmin(LL& x,LL y){if(x>y)x=y;}
LL read(){
	LL x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch-'0');ch=getchar();}
	return f*x;
}
const LL maxn=605000,inf=1000000000;
struct cp{
	db x,y;
	cp(db x=0,db y=0):x(x),y(y){}
	cp operator+(const cp& b){return cp(x+b.x,y+b.y);}
	cp operator-(const cp& b){return cp(x-b.x,y-b.y);}
	cp operator*(const cp& b){return cp(x*b.x-y*b.y,x*b.y+y*b.x);}
}a[maxn],b[maxn],w[maxn];
db pi=(acos(-1.0));
LL H=0,L=1,R[maxn],c[maxn],d[maxn];
void FFT(cp* a,LL f){
	for(LL i=0;i<L;i++)if(i<R[i])swap(a[i],a[R[i]]);
	for(LL len=2;len<=L;len<<=1){
		LL l=len>>1;
		cp wn(cos(pi/l),f*sin(pi/l));
		for(LL i=1;i<l;i++)w[i]=w[i-1]*wn;
		for(LL st=0;st<L;st+=len)
			for(LL k=0;k<l;k++){
				cp x=a[st+k],y=w[k]*a[st+k+l];
				a[st+k]=x+y,a[st+k+l]=x-y;
			}
	}
	if(f==-1)for(LL i=0;i<L;i++)a[i].x/=L;
}
LL n;
int main(){
	freopen("dealing.in","r",stdin);
	freopen("dealing.out","w",stdout);
	w[0].x=1;
	n=read();
	for(H=0,L=1;L<n<<2;H++)L<<=1;
	up(i,0,n-1)scanf("%lf",&a[i].x);
	up(i,0,n-1)b[i+n].x=!i?0:1.0/(i)/(i);
	for(int i=n-1;i>=0;i--)b[i].x=-1.0/(n-i)/(n-i);
	for(LL i=0;i<L;i++)R[i]=(R[i>>1]>>1)|((i&1)<<(H-1));
	FFT(a,1);FFT(b,1);
	for(int i=0;i<L;i++)a[i]=a[i]*b[i];
	FFT(a,-1);
	up(i,n,(n<<1)-1)printf("%.3lf\n",a[i].x);
	return 0;
}

  

posted @ 2017-03-04 23:28  CHADLZX  阅读(97)  评论(0编辑  收藏  举报