LuoguP3338 [ZJOI2014]力
题目描述
给出n个数qi,给出Fj的定义如下:
\]
令\(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]力的更多相关文章
- [ZJOI3527][Zjoi2014]力
[ZJOI3527][Zjoi2014]力 试题描述 给出n个数qi,给出Fj的定义如下: 令Ei=Fi/qi.试求Ei. 输入 包含一个整数n,接下来n行每行输入一个数,第i行表示qi. 输出 有n ...
- bzoj3527: [Zjoi2014]力 fft
bzoj3527: [Zjoi2014]力 fft 链接 bzoj 思路 但是我们求得是 \(\sum\limits _{i<j} \frac{q_i}{(i-j)^2}-\sum_{i> ...
- 洛谷 P3338 [ZJOI2014]力 解题报告
P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \(F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_{i>j ...
- 【BZOJ 3527】 3527: [Zjoi2014]力 (FFT)
3527: [Zjoi2014]力 Time Limit: 30 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 2003 Solved: 11 ...
- [洛谷P3338] [ZJOI2014]力
洛谷题目链接:P3338 [ZJOI2014]力 题目描述 给出n个数qi,给出Fj的定义如下: \[F_j = \sum_{i<j}\frac{q_i q_j}{(i-j)^2 }-\sum_ ...
- P3338 [ZJOI2014]力(FFT)
题目 P3338 [ZJOI2014]力 做法 普通卷积形式为:\(c_k=\sum\limits_{i=1}^ka_ib_{k-i}\) 其实一般我们都是用\(i=0\)开始的,但这题比较特殊,忽略 ...
- [Luogu P3338] [ZJOI2014]力 (数论 FFT 卷积)
题面 传送门: 洛咕 BZOJ Solution 写到脑壳疼,我好菜啊 我们来颓柿子吧 \(F_j=\sum_{i<j}\frac{q_i*q_j}{(i-j)^2}-\sum_{i>j} ...
- 笔记-[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}{ ...
- 【BZOJ】3527: [Zjoi2014]力 FFT
[参考]「ZJOI2014」力 - FFT by menci [算法]FFT处理卷积 [题解]将式子代入后,化为Ej=Aj-Bj. Aj=Σqi*[1/(i-j)^2],i=1~j-1. 令f(i)= ...
随机推荐
- NOIp2018集训test-9-1(am)
1.最大值 可以用FWT水过去,李巨写了FWT结果中途爆int了炸了几十分好像. 我乱搞了一下把除了大数据有or的搞出来然后90,还是蛮划算的.我yy的做法: 1.xor 字典树上贪心, 一开始我打了 ...
- Spring-Security (学习记录一)--登录
目录 创建maven工程 1. 在pom.xml中加入相关jar包的配置 2.添加spring-security.xml文件 3.新建admin和user文件夹 4.配置web.xml文件 5.访问 ...
- VScode中写vue代码 Ctrl+/添加注释失效
1.点击列表的文件——>首选项——>键盘快捷方式,在里面查看 Ctrl+/ 是否有冲突 2.查看右下角的选择语言模式是否是Vue,如下图
- AdaBoost笔记之通俗易懂原理介绍
转自:https://blog.csdn.net/px_528/article/details/72963977 写在前面 说到Adaboost,公式与代码网上到处都有,<统计学习方法>里 ...
- nginx分布式实例入门操作
本文目的 前段时间学习WCF已经渐入佳境,完成了既定学习目标,转入分布式系统学习.本文技术路线是: 采用wcf实现分布式服务端和客户端,客户端部署于本地主机,nginx和WCF部署于虚拟机端(分别是三 ...
- 如何查看jdk版本和路径
cmd进入命令提示符,查看jdk版本,输入java -version;查看jdk路径 ,输入set java home.,这个也是默认路径
- matplotlib画图出现乱码情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...
- Error resolving template,template might not exist or might not be accessible by any of the configured Template Resolvers
template might not exist or might not be accessible by any of the configured Template Resolvers at o ...
- 我写的第一个DELPHI的控制台程序,留作纪念。
program Project2; {$APPTYPE CONSOLE} uses SysUtils; const s = 'hello' ; var a , b , c : integer; f ...
- java 一维数组的输出方式
1.使用传统的for()循环输出: //定义一个数组 int []array = {1,2,3,4,5}; for(int i=0;i<array.length;i++) { System.ou ...