题目描述

给出n个数qi,给出Fj的定义如下:

\[F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j}\frac{q_i q_j}{(i-j)^2 }
\]

令\(E_i=\frac{F_i}{q_i}\),求\(E_i\).

输入输出格式

输入格式:

第一行一个整数n。

接下来n行每行输入一个数,第i行表示qi。

输出格式:

n行,第i行输出Ei。

与标准答案误差不超过1e-2即可。

输入输出样例

输入样例#1:

5

4006373.885184

15375036.435759

1717456.469144

8514941.004912

1410681.345880

输出样例#1:

-16838672.693

3439.793

7509018.566

4595686.886

10903040.872

说明

对于30%的数据,n≤1000。

对于50%的数据,n≤60000。

对于100%的数据,n≤100000,0<qi<1000000000。

[spj 0.01]

题解

https://www.cnblogs.com/iwtwiioi/p/4126284.html

看这个题解吧。。

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
inline void swap(int &a, int &b){int tmp = a;a = b;b = tmp;}
inline void swap(double &a, double &b){double tmp = a;a = b;b = tmp;}
inline void read(int &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const int MAXN = 1 << 18;
const double PI = acos(-1);
struct Complex
{
double real, imag;
Complex(double _real, double _imag){real = _real, imag = _imag;}
Complex(){real = imag = 0;}
Complex operator+(const Complex &x) const {return Complex(real + x.real, imag + x.imag);}
Complex operator-(const Complex &x) const {return Complex(real - x.real, imag - x.imag);}
Complex operator*(const Complex &x) const {return Complex(real * x.real - imag * x.imag, real * x.imag + imag * x.real);}
Complex& operator*=(const Complex &x) {return *this = (*this) * x;}
};
int n, m, tn, len, rev[MAXN], tmp;
Complex a[MAXN], b[MAXN], c[MAXN];
double q[MAXN];
void fft(Complex *arr, int f)
{
for(int i = 0; i < n; i++) if(i < rev[i]) std::swap(arr[i], arr[rev[i]]);
for(int i = 1; i < n; i <<= 1)
{
Complex wn(cos(PI / i), f * sin(PI / i));
for(int j = 0; j < n; j += i << 1)
{
Complex w(1, 0);
for(int k = 0; k < i; k++)
{
Complex x = arr[j + k], y = w * arr[j + k + i];
arr[j + k] = x + y;
arr[j + k + i] = x - y;
w *= wn;
}
}
}
if(f == -1) for(int i = 0;i < n;++ i) arr[i].real /= n;
}
int main()
{
read(n), -- n, tn = n;
for(int i = 0;i <= tn;++ i) scanf("%lf", &q[i]); for(int i = 0;i <= tn;++ i) a[i].real = q[i], c[i].real = q[tn - i];
for(int i = 1;i <= tn;++ i) b[i].real = (double)1.0/i/i;
m = tn + tn;
for(n = 1;n <= m;n <<= 1) ++ len; for(int i = 0; i < n; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (len - 1));
fft(a, 1), fft(b, 1), fft(c, 1);
for(int i = 0;i <= n;++ i) a[i] *= b[i], c[i] *= b[i];
fft(a, -1), fft(c, -1); for(int i = 0;i <= tn;++ i)
printf("%.3lf\n", a[i].real - c[tn - i].real);
return 0;
}

LuoguP3338 [ZJOI2014]力的更多相关文章

  1. [ZJOI3527][Zjoi2014]力

    [ZJOI3527][Zjoi2014]力 试题描述 给出n个数qi,给出Fj的定义如下: 令Ei=Fi/qi.试求Ei. 输入 包含一个整数n,接下来n行每行输入一个数,第i行表示qi. 输出 有n ...

  2. bzoj3527: [Zjoi2014]力 fft

    bzoj3527: [Zjoi2014]力 fft 链接 bzoj 思路 但是我们求得是 \(\sum\limits _{i<j} \frac{q_i}{(i-j)^2}-\sum_{i> ...

  3. 洛谷 P3338 [ZJOI2014]力 解题报告

    P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \(F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j ...

  4. 【BZOJ 3527】 3527: [Zjoi2014]力 (FFT)

    3527: [Zjoi2014]力 Time Limit: 30 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 2003  Solved: 11 ...

  5. [洛谷P3338] [ZJOI2014]力

    洛谷题目链接:P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \[F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_ ...

  6. P3338 [ZJOI2014]力(FFT)

    题目 P3338 [ZJOI2014]力 做法 普通卷积形式为:\(c_k=\sum\limits_{i=1}^ka_ib_{k-i}\) 其实一般我们都是用\(i=0\)开始的,但这题比较特殊,忽略 ...

  7. [Luogu P3338] [ZJOI2014]力 (数论 FFT 卷积)

    题面 传送门: 洛咕 BZOJ Solution 写到脑壳疼,我好菜啊 我们来颓柿子吧 \(F_j=\sum_{i<j}\frac{q_i*q_j}{(i-j)^2}-\sum_{i>j} ...

  8. 笔记-[ZJOI2014]力

    [ZJOI2014]力 \[\begin{split} E_j=&\sum_{i=1}^{j-1}\frac{q_i}{(i-j)^2}-\sum_{i=j+1}^{n}\frac{q_i}{ ...

  9. 【BZOJ】3527: [Zjoi2014]力 FFT

    [参考]「ZJOI2014」力 - FFT by menci [算法]FFT处理卷积 [题解]将式子代入后,化为Ej=Aj-Bj. Aj=Σqi*[1/(i-j)^2],i=1~j-1. 令f(i)= ...

随机推荐

  1. js Date.parse() format.

    date format android chrome linux chrome Mobile safari ios chrome windows safari linux firefox window ...

  2. Django中的HttpResponse和JsonResponse

    Django中的HttpResponse和JsonResponse 我们在编写一些借口函数的时候,经常需要给调用者返回json格式的数据,那么如何返回可直接解析的数据呢? 首先第一种方式: from ...

  3. C不同变量类型存储大小引发的BUG

    #include"stdio.h" typedef signed char int8; typedef unsigned char uint8; typedef signed sh ...

  4. 常用的一些 linux 指令

    1. mv linux下重命名文件或文件夹使用mv既可实现. 1.1 重命名 a.将一个名为abc.txt的文件重命名为1234.txt #mv abc.txt .txt b. 将目录A重命名为B ( ...

  5. MySQL初步理解,简易单表增删改查

    什么是数据库? 存储数据的仓库,本质是一个文件系统,封装了算法和文件之前数据的存储模式 阶段1:集合 数组 变量 缺点:数据存储在内存中,不能实现数据的持久化存储 阶段2:IO流 结合文件 .txt ...

  6. 2019-3-16-win10-uwp-在-ItemsPanelTemplate-里面通过样式绑定-Orientation-显示方向

    title author date CreateTime categories win10 uwp 在 ItemsPanelTemplate 里面通过样式绑定 Orientation 显示方向 lin ...

  7. (转)Google Protocol Buffer 的使用和原理

    转自:https://www.ibm.com/developerworks/cn/linux/l-cn-gpb/index.html   简介 什么是 Google Protocol Buffer? ...

  8. node---处理get请求

    const http=require('http') const querystring=require('querystring') const server = http.createServer ...

  9. css---文本新增样式

    opacity属性指定了一个元素的透明度 默认值:1.0 不可继承    兼容性不是太好 兼容性写法 opacity{ opacity:0.5; filter:alpha(opacity=); //f ...

  10. ubuntu下安装git提示无root权限

    apt-get install git 获取git指令 sudo passwd root 重置unix密码 su root 键入密码 参考链接 https://www.cnblogs.com/2she ...