XTU 1249 Rolling Variance
Rolling Variance
Accepted : 77 | Submit : 212 | |
Time Limit : 3000 MS | Memory Limit : 65536 KB Special Judge |
Rolling Variance
Bobo learnt that the variance of a sequence a1,a2,…,an is
where
Bobo has a sequence a1,a2,…,an,and he would like to find the variance of each consecutive subsequences of length m.Formally, the i-th (1≤i≤n−m+1) rolling variance ri is the variance of sequence {ai,ai+1,…,ai+m−1}.
Input
The input contains at most 30 sets. For each set:
The first line contains 2 integers n,m (2≤m≤n≤105).
The second line contains n integers a1,a2,…,an (|ai|≤100).
Output
For each set, (n−m+1) lines with floating numbers r1,r2,…,rn−m+1.
Your answer will be considered correct if its absolute or relative error does not exceed 10−4.
Sample Input
3 2 1 3 2 5 3 1 3 2 4 5
Sample Output
1.41421356 0.70710678 1.00000000 1.00000000 1.52752523
解题思路:先求出m个连续的数的平均值a,然后求(ai-a)^2
求和:(a0+a)^2+(a1+a)^2+(a2+a)^2+(a3+a)^2+···
=a0^2+2*a*a0+a^2+a1^2+2*a*a1+a^2+a2^2+2*a*a2+a^2+·····
=(a0^2+a1^2+····)+a2^2+2*a*(a0+a1+a2+····)+(a^2+a^2+a^2+·····)
代码如下:
#include <stdio.h>
#include <math.h>
#include <string.h>
#define maxn 100001
int a[maxn],b[maxn];
int main()
{int n,m,c;while(scanf("%d %d",&n,&m)!=EOF){int i;for(i=1; i<=n; i++){scanf("%d",&c);a[i]=a[i-1]+c;///前i个数的和b[i]=b[i-1]+c*c;///前i个数的平方和}for(i=m; i<=n;i++){double s=0;s=1.0*(a[i]-a[i-m])/(1.0*m);///求出平均数s=b[i]-b[i-m]+s*s*m-2.0*s*(a[i]-a[i-m]);printf("%0.8lf\n",(double)sqrt(s/(m-1)));}}return 0;
}
aa¯
XTU 1249 Rolling Variance相关推荐
- 使用r语言做garch模型_使用GARCH估计货币波动率
使用r语言做garch模型 Asset prices have a high degree of stochastic trends inherent in the time series. In o ...
- Pandas Window对象
生成window对象 .rolling calls:pandas.DataFrame.rolling(),pandas.Series.rolling() .expanding calls:pandas ...
- 用python做时间序列预测十:时间序列实践-航司乘客数预测
本文以航司乘客数预测的例子来组织相关时间序列预测的代码,通过了解本文中的代码,当遇到其它场景的时间序列预测亦可套用. 航司乘客数序列 预测步骤 # 加载时间序列数据 _ts = load_data() ...
- bokeh pandas_使用Pandas和Bokeh将Rolling Stone的500张最伟大专辑可视化
bokeh pandas by Gautham Koorma 通过Gautham Koorma 使用Pandas和Bokeh将Rolling Stone的500张最伟大专辑可视化 (Rolling S ...
- hung-yi lee_p4_Bias And Variance
文章目录 本节目的 bias variance 结论(鱼和熊掌不可得兼) 如何解决 减小bias的方案 减小variance的方案 对训练集进行处理得到更好的模型 本节目的 where does th ...
- 在线作图丨高级的微生物分析——在线做Variance Partitioning Analysis(VPA分析)
今天小编给大家分享点厉害的干货~ Question 1:什么是VPA? 群落分析中常见的环境因子分析包括CCA典范对应分析(canonical correspondence analysis)和RDA ...
- pandas使用groupby函数计算dataframe数据中每个分组的N个数值的滚动最大值(rolling max)、例如,计算某公司的多个店铺每N天(5天)的滚动销售额最大值
pandas使用groupby函数计算dataframe数据中每个分组的N个数值的滚动最大值(rolling max).例如,计算某公司的多个店铺每N天(5天)的滚动销售额最大值 目录
- pandas中使用rolling.corr函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations)、例如,计算两种商品销售额之间的3个月的滚动相关性
pandas中使用rolling.corr函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations).例如,计算两种商品销售额之间的3个月的滚动相关性 目录
- excel中使用CORREL函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations)、例如,计算两种商品销售额之间的3个月的滚动相关性
excel中使用CORREL函数计算两个时间序列数据列之间的滚动相关性(Rolling correlations).例如,计算两种商品销售额之间的3个月的滚动相关性 目录
最新文章
- Android中Context 的理解
- 探索C#之布隆过滤器(Bloom filter)
- 重读ORB_SLAM之Tracking线程难点
- (转)Java中的private、protected、public和default的区别
- 文字超出部分显示..._matplotlib图形内的文字、注释、箭头
- JBoss4.2.3GA 配置 Quartz
- 下载python教程-零基础Python教程全集下载.pdf
- 如何提升数据分析的效率
- 秒赞机器人好友_qq空间秒赞机器人好友 qq空间说说秒赞神器
- 算法工程师面试题总结
- 什么是Apache APR
- 以太坊的区块和存储(二):区块体之叔区块
- kubernetes install completed
- 如何编写GIMP插件(三)
- 2020计算机专业评估,2020年计算机学科大学排名TOP50,实力强,毕业生认可度高...
- 产品新创意,创意产品原型大公开,原来可以这样做!
- Excel 里筛选手机号码所属运营商
- 如何远程登陆Linux服务器
- 最全的肱三头肌训练图解,漂亮手臂必备
- LLDP协议、STP协议 笔记