【FFT】HDU 4609

给定集合,求任选三个数能构成三角形的概率


#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define rep(i,l,r) for(int i=(l),_=(r);i<=_;i++)
#define per(i,r,l) for(int i=(r),_=(l);i>=_;i--)
#define MS(arr,x) memset(arr,x,sizeof(arr))
#define INE(i,u) for(int i=head[u];~i;i=e[i].next)
#define LL long long
inline const int read(){int r=0,k=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1;
for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return r*k;}
//
const double PI=acos(-1.0);
const int N=400010;
int n,a[N];
LL c[N],s[N];
struct Complex{
	double r,i;
	Complex(double _r=0,double _i=0){r=_r;i=_i;}
	Complex operator+(const Complex &b){return Complex(r+b.r,i+b.i);}
	Complex operator-(const Complex &b){return Complex(r-b.r,i-b.i);}
	Complex operator*(const Complex &b){return Complex(r*b.r-i*b.i,r*b.i+i*b.r);}
}x[N];
//
void bitreverse(Complex a[],int n)
{
	for(int i=1,j=0;i>1;k>(j^=k);k>>=1);
		if(i>=1;
	rep(i,1,len) s[i]=s[i-1]+c[i];
	LL cnt=0,tot=(LL)n*(n-1)*(n-2)/6;
	rep(i,1,n)
	{
		cnt+=s[len]-s[a[i]];
		cnt-=(LL)(n-i)*(i-1);
		cnt-=n-1;
		cnt-=(LL)(n-i)*(n-i-1)/2;
	}
	printf("%.7lf\n",(double)cnt/tot);
}
//
int main()
{
	rep(i,1,read())
	input(),solve();
	return 0;
}


你可能感兴趣的:(代码)