Kattis A+B Problem(FFT)

Kattis A+B Problem(FFT)_第1张图片


题意:求n个数中任取三个组合成ai+aj=ak 的对数
思路:把给的数作为多项式的次幂,出现的次数为系数,然后用FFT进行多项式的乘法
#include 
#include 
#include 
#include 
#include 
#include 
#define maxn (1<<20)
#define pi 3.141592653589793238462643383
#define M 50000
using namespace std;
int p[1000100],n,zero=0,ma=0;
long long ans=0;
struct complex
{
	double re,im;
	complex(double r=0.0,double i=0.0) {re=r,im=i;}
	void print() {printf("%.lf ",re);}
} a[maxn*2],b[maxn*2],W[2][maxn*2],c[maxn*2];

int N,na,nb,rev[maxn*2];

complex operator +(const complex&A,const complex&B) {return complex(A.re+B.re,A.im+B.im);}
complex operator -(const complex&A,const complex&B) {return complex(A.re-B.re,A.im-B.im);}
complex operator *(const complex&A,const complex&B) {return complex(A.re*B.re-A.im*B.im,A.re*B.im+A.im*B.re);}

void FFT(complex*a,int f)
{
	complex x,y;
	for (int i=0; i>=1,k<<=1) (y<<=1)|=x&1;
		rev[i]=y;
	}
	for (int i=0; i


你可能感兴趣的:(算法学习)