题目描述
给出n个数qi,给出Fj的定义如下:
对式子变形,再利用多项式卷积。FFT。
然后把 φ 和 ω 给求出来就OK了。
#include
using namespace std ;
const int maxn = 400005 ;
const double PI = acos(-1.0) ;
int n, m, dep, rev[maxn], len ;
double q[maxn], g[maxn], p[maxn], ans[maxn] ;
complex <double> a[maxn], b[maxn] ;
void DFT ( complex <double> a[], int len, int t ) {
int i, j, k ;
for ( i = 1 ; i < len ; i ++ ) if ( ifor ( j = 1 ; j < len ; j <<= 1 ) {
complex <double> dw( cos(2*PI/(j<<1)), sin(2*t*PI/(j<<1)) ) ;
for ( i = 0 ; i < len ; i += (j<<1) ) {
complex <double> w(1,0), t0, t1 ;
for ( k = 0 ; k < j ; k ++, w *= dw ) {
t0 = a[i+k] ;
t1 = w*a[i+k+j] ;
a[i+k] = t0+t1 ;
a[i+j+k] = t0-t1 ;
}
}
}
for ( i = 0 ; i <= len && t == -1 ; i ++ ) a[i] /= len ;
}
void FFT ( double x[], double y[], complex<double> a[], complex<double> b[], complex <double> c[], int len ) {
int i ;
for ( i = 0 ; i < len ; i ++ ) a[i] = x[i] ;
for ( i = 0 ; i < len ; i ++ ) b[i] = y[i] ;
DFT ( a, len, 1 ) ; DFT ( b, len, 1 ) ;
for ( i = 0 ; i < len ; i ++ ) c[i] = a[i]*b[i] ;
DFT ( c, len, -1 ) ;
}
void init() {
int i, j, k = 0 ;
len = n<<1|1 ;
for ( k = 1 ; k <= len ; k <<= 1 ) ++ dep ;
len = k ;
for ( i = 1 ; i < len ; i ++ ) rev[i] = (rev[i>>1]>>1)|((i&1)<1) ;
}
int main() {
int i, j, k ;
scanf ( "%d", &n ) ;
for ( i = 1 ; i <= n ; i ++ ) scanf ( "%lf", q+i ) ;
for ( p[0] = q[n], i = 1 ; i <= n ; i ++ ) g[i] = 1.0/(i*i), p[i] = q[n-i] ;
init() ;
FFT ( q, g, a, b, a, len ) ;
for ( i = 0 ; i <= n ; i ++ ) ans[i] = a[i].real() ;
FFT ( p, g, a, b, a, len ) ;
for ( i = 0 ; i <= n ; i ++ ) ans[i] -= a[n-i].real() ;
for ( i = 1 ; i <= n ; i ++ ) printf ( "%.3lf\n", ans[i] ) ;
return 0 ;
}