Rolling Variance
2016-06-26 16:06
363 查看
题目链接 http://202.197.224.59/OnlineJudge2/index.php/Contest/read_problem/cid/41/pid/1249
Input
Output
Sample Input
Sample Output
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
Main(A,n,m): For i=1 to n-m+1 Sub_ Sum = 0 For j=i to i+m-1 Sub_ Sum = Sub_ Sum + A[j] Average =Sub_ Sum /m Sub_denom = 0 For j=I to i+m-1 Sub_denom = Sub_denom + (A[j]-Average)^2 Print sqrt[Sub_denom/(m-1)]
Main(A,n,m) Array Sub_Sum[n-m+1],Sub_Ave [n-m+1],Sub_Quasum [n-m+1] Sub_Sum[1]=0 Sub_Quasum [1]=0 For i=1 to m Sub_Sum[1] = Sub_Sum[1] + A[i] Sub_Quasum [1] = Sub_Quasum [1] + A[i]*A[i] Sub_Ave[1] = Sub_Sum[1]/m For j=2 to n-m+1 Sub_Sum[j] = Sub_Sum[j] – A[j-1] + A[j+m-1] Sub_Quasum [j] = Sub_Quasum [j] – A[j-1]*A[j-1] + A[j-m+1]*A[j-m+1] Sub_Ave[j] = Sub_Sum[j]/m For i=1 to n-m+1 ans=Sub_Quasum [i]–2*Sub_Ave[i]* Sub_Sum[i]+m*Sub_Ave[i]* Sub_Ave[i] ans/m-1 Print sqrt(ans) //但是比赛时各种RE,最后把数组开到了 2.5*10^5 (题目数据范围的2倍)才过,也不知道是不是题目数据大了
相关文章推荐
- WebService三大基本元素 SOAP WSDL UDDI
- python - 类的特殊成员
- URL和URI的区别和联系
- KMP
- 1A. Theatre Square
- C++拷贝构造函数详解
- ajax练习习题三搜索
- GDB技巧整理
- 1A. Theatre Square
- 二叉搜索树(Binary Search Tree)
- 玩转京东暨618狂欢节回顾
- git 新建服务器的版本以及项目的用户
- Chapter 2 命令行基础(1)
- 派生类的构造函数
- GIT——乱乱的理解
- 【初探】排序算法
- poj3352 Road Construction
- GCC相关的环境变量
- Wildcard Matching
- 亦大自学51cto--网络工程师成长之路前沿