cf 808B
来源:互联网 发布:js createevent 编辑:程序博客网 时间:2024/05/22 03:25
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lastsk days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the lastn days. So now he has a sequence a1, a2, ..., an, whereai is the sleep time on thei-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to considerk consecutive days as a week. So there will ben - k + 1 weeks to take into consideration. For example, ifk = 2, n = 3 anda = [3, 4, 7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks.
The first line contains two integer numbers n andk (1 ≤ k ≤ n ≤ 2·105).
The second line contains n integer numbersa1, a2, ..., an (1 ≤ ai ≤ 105).
Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.
3 23 4 7
9.0000000000
1 110
10.0000000000
8 21 2 4 100000 123 456 789 1
28964.2857142857
In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.
ac代码:
#include <iostream> #include <cstring> #include <cstdio> typedef long long ll; using namespace std; int n,k; long long s[200005]; long long a[200005]; int main() { int n,k; cin>>n>>k; s[0]=0; for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); s[i]=s[i-1]+a[i]; } double res = 0; for(int i=k;i<=n;i++){ res+=s[i]-s[i-k]; } printf("%.6lf\n",res/(n-k+1)); return 0; }
- cf 808B
- cf-B
- cf B
- CF 1B Spreadsheet
- CF 3B Lorry
- CF 176B
- CF 91B
- cf 131 DIV2 B
- CF 113B || CF196D
- CF 126B
- CF-236B
- CF 254B(日期)
- cf 79B
- CF - 158B - Taxi
- CF 296B
- CF 173(div2) B
- cf:B-QR code
- cf 1B. Spreadsheets
- SpringHibernate异常
- html5 验证码倒计时
- 构造方法的重载举例
- vue移动端裁剪图片结合插件Cropper的使用
- Java基础01概念及环境配置
- cf 808B
- wstring与string相互转换
- 图线画线三种技术
- java中判断字符串是否为数字的方法的几种方法
- 有向图最大影响力的顶点_OJ实践笔记
- 【Java编码规范】《阿里巴巴Java开发手册(正式版)》更新(v1.1.1版)
- 96-ICMP 协议(时间戳请求与应答)
- PHP操作数据库(插入数据)
- 算法导论 练习题 15.2-2