CF1398G Running Competition FFT

求最大的 $2(a_{i}-a_{j}+y)|L$.     

其中 $a_{i}-a_{j}$ 只可能有 $x$ 种结果.  

这个显然可以用 FFT 来算可行性.    

然后调和级数更新就可以了.       

FFT 中复数的运算什么的要注意一下,不要写错.   

单位根是 $(cos(\frac{pi}{l}),i*sin(\frac{pi}{l}))$   

代码: 

#include  
#define N 1000009  
#define ll long long 
#define setIO(s) freopen(s".in","r",stdin) 
using namespace std; 
int n,bu[N];     
const double pi=acos(-1);  
struct cp {
	double x,y;  
	cp(double i=0,double j=0){ x=i,y=j; }         
	cp operator+(const cp b) const { return cp(x+b.x,y+b.y); }
	cp operator-(const cp b) const { return cp(x-b.x,y-b.y); }
	cp operator*(const cp b) const { return cp(x*b.x-y*b.y,x*b.y+y*b.x); }
}A[N],B[N];  
void FFT(cp *a,int len,int op) {
	for(int i=0,k=0;ik) swap(a[i],a[k]); 
		for(int j=len>>1;(k^=j)>=1);    
	}
	for(int l=1;l 
   

  

你可能感兴趣的:(CF1398G Running Competition FFT)