首页 技术 正文
技术 2022年11月16日
0 收藏 783 点赞 3,332 浏览 1692 个字

题面

题解:

\[F_j = \sum_{i < j}\frac{q_iq_j}{(i – j)^2} – \sum_{i > j}{\frac{q_iq_j}{(i – j)^2}}
\]

\[E_j = \sum_{i < j}\frac{q_i}{(i – j)^2} – \sum_{i > j}{\frac{q_i}{(i – j)^2}}
\]

对式子的2个部分分别计算。

令\(S_i = i^2\)

\[\sum_{i < j}\frac{q_i}{(i – j)^2} = \sum_{i < j}q_i S_{j – i}
\]

看上去就是卷积形式,FFT计算即可。

对于后半部分,将序列翻转,\(i > j\)就变成\(i < j\)了,而\(S\)可以看做距离,所以不会变,直接计算就好了.

计算完之后需要将序列翻转回来

#include<bits/stdc++.h>
using namespace std;
#define R register int
#define ld double
#define LL long long
#define AC 310000const double pi = acos(-1);
int n, lim = 1, len;
int Next[AC];
ld q[AC], f[AC];struct node{
ld x, y;
node(ld xx = 0, ld yy = 0){x = xx, y = yy;}
}a[AC], b[AC], s[AC];node operator * (node x, node y){return node(x.x * y.x - x.y * y.y, x.x * y.y + x.y * y.x);}
node operator + (node x, node y){return node(x.x + y.x, x.y + y.y);}
node operator - (node x, node y){return node(x.x - y.x, x.y - y.y);}inline int read()
{
int x = 0;char c = getchar();
while(c > '9' || c < '0') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}void FFT(node *A, int opt)
{
for(R i = 0; i < lim; i ++)
if(i < Next[i]) swap(A[i], A[Next[i]]);
for(R i = 1; i < lim ; i <<= 1)
{
node W(cos(pi / i), opt * sin(pi / i));
for(R r = i << 1, j = 0; j < lim; j += r)
{
node w(1, 0);
for(R k = 0; k < i ; k ++, w = w * W)
{
node x = A[j + k], y = w * A[j + k + i];
A[j + k] = x + y, A[j + k + i] = x - y;
}
}
}
}void pre()
{
n = read() - 1;
for(R i = 0; i <= n; i ++) scanf("%lf", &q[i]);
while(lim <= n + n) lim <<= 1, ++ len;
for(R i = 0; i <= lim; i ++)
Next[i] = (Next[i >> 1] >> 1) | ((i & 1) << (len - 1));
}void work()
{
for(R i = 0; i <= n; i ++)
{
if(i != 0) s[i].x = 1.0 / i / i;
a[i].x = q[i], b[n - i].x = q[i];
}
FFT(s, 1);
FFT(a, 1);
for(R i = 0; i < lim; i ++) a[i] = a[i] * s[i];
FFT(a, -1);
for(R i = 0; i < lim; i ++) f[i] = a[i].x / lim;
FFT(b, 1);
for(R i = 0; i < lim; i ++) b[i] = b[i] * s[i];
FFT(b, -1);
for(R i = 0; i <= n; i ++)
if(i < n - i) swap(b[i], b[n - i]);
for(R i = 0; i < lim; i ++) f[i] -= b[i].x / lim;
for(R i = 0; i <= n; i ++) printf("%.3lf\n", f[i]);
}int main()
{
//freopen("in.in", "r", stdin);
pre();
work();
//fclose(stdin);
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,955
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774