bzoj3527: [Zjoi2014]力

一句话:给出n个数qi,给出Fj的定义如下: 
 

令Ei=Fi/qi,求Ei


思路:先把q[i]约了,然后就是:


Ei=j<iqj(ji)2j>iqj(ji)2


先看左边:

令f[i]=q[i],g[i]=1/i/i

左边就是sigma f[j]*g[i-j] 

然后下标和就为定值了,就是卷积了,上FFT搞一搞

右边把q反过来再上FFT搞一搞


j<i

#include
#include
#include
#include
#include
const double pi=M_PI;
const int maxn=270010;
using namespace std;
struct plex{
	double r,i;
}tmp[maxn];
plex operator +(plex a,plex b){return (plex){a.r+b.r,a.i+b.i};}
plex operator -(plex a,plex b){return (plex){a.r-b.r,a.i-b.i};}
plex operator *(plex a,plex b){return (plex){a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r};}
int n,nn;double q[maxn],ans[maxn];

struct DFT{
	plex a[maxn];
	void fft(int bg,int step,int size,int op){
		if (size==1) return;
		fft(bg,step<<1,size>>1,op),fft(bg+step,step<<1,size>>1,op);
		plex w=(plex){1,0},t=(plex){cos(2*pi/size),sin(2.0*pi*op/size)};
		int p=bg,p0=bg,p1=bg+step;
		for (int i=0;i



j<i

转载于:https://www.cnblogs.com/thythy/p/5493576.html

你可能感兴趣的:(bzoj3527: [Zjoi2014]力)