HYSBZ 3527 力
题目描述:
输入一个数列
qi (1<i<N)
,令:
Fj=∑i<jqiqj(i−j)2−∑i>jqiqj(i−j)2
计算所有 Ei=Fiqi 。
题解:
打表,脑补之后发现,构造函数:
A(x)=∑i=0i<Nqi+1xiB(x)=∑i=Ni<2N−2xi(i−N+1)2−∑i=0i<N−1xi(N−i−1)2
Ei 就等于 A⋅B 的 i+N−1 次项系数。FFT即可。
代码:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 1000010
const double pi = acos(-1);
static struct tComplex
{
double x, y;
tComplex(): x(0), y(0) {}
tComplex(double a, double b): x(a), y(b) {}
friend tComplex operator + (tComplex a, tComplex b)
{
return tComplex(a.x + b.x, a.y + b.y);
}
friend tComplex operator - (tComplex a, tComplex b)
{
return tComplex(a.x - b.x, a.y - b.y);
}
friend tComplex operator * (tComplex a, tComplex b)
{
return tComplex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
} A[MAXN], B[MAXN];
static int N, L, binL, R[MAXN];
inline void FFT(tComplex A[], int type)
{
for (int i = 0; i < binL; i++)
if (R[i] > i) swap(A[i], A[R[i]]);
for (int i = 1; i < binL; i <<= 1)
{
tComplex wn = tComplex(cos(pi / i), sin(type * pi / i));
for (int j = 0; j < binL; j += (i << 1))
{
tComplex w = tComplex(1, 0);
for (int k = 0; k < i; k++, w = w * wn)
{
tComplex x = A[j + k], y = A[i + j + k] * w;
A[j + k] = x + y;
A[i + j + k] = x - y;
}
}
}
if (!~type)
for (int i = 0; i < binL; i++) A[i].x /= (double)binL;
}
int main()
{
scanf("%d", &N);
N--;
for (int i = 0; i <= N; i++) scanf("%lf", &A[i].x);
for (int i = 0; i < N; i++) B[i].x = (-1.0) / ((long long)(N - i) * (N - i));
for (int i = N + 1; i <= 2 * N; i++) B[i].x = -B[2 * N - i].x;
for (L = 0, binL = 1; binL <= 4 * N; L++, binL <<= 1);
for (int i = 0; i < binL; i++)
R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
FFT(A, 1);
FFT(B, 1);
for (int i = 0; i <= binL; i++) A[i] = A[i] * B[i];
FFT(A, -1);
for (int i = N; i <= 2 * N; i++) printf("%.3lf\n", A[i].x);
return 0;
}
提交记录(AC / Total = 1 / 1):
| Run ID | Remote Run ID | Time(ms) | Memory(kb) | Result | Submit Time |
|---|---|---|---|---|---|
| 8524850 | 1940840 | 3864 | 35976 | AC | 2017-03-22 20:28:13 |
251

被折叠的 条评论
为什么被折叠?



