MAX Average Problem

Time Limit: 3000ms
Memory Limit: 65536KB

64-bit integer IO format: %lld      Java class name: Main

 

Consider a simple sequence which only contains positive integers as a1, a2 ... an, and a number k. Define ave(i,j) as the average value of the sub sequence ai ... aj, i<=j. Let’s calculate max(ave(i,j)), 1<=i<=j-k+1<=n.

 

Input

There multiple test cases in the input, each test case contains two lines.
The first line has two integers, N and k (k<=M<=10^5).
The second line has N integers, a1, a2 ... an. All numbers are ranged in [1, 2000].

 

Output

For every test case, output one single line contains a real number, which is mentioned in the description, accurate to 0.01.

 

Sample Input

10 6
6 4 2 10 3 8 5 9 4 1

Sample Output

6.50

Source

Author

HK@Sphinx
 
解题:单调队列+斜率优化
 
 #include <stdio.h>
#include <iostream>
using namespace std;
typedef long long LL;
const int maxn = ;
int q[maxn],hd,tl,n,k;
LL sum[maxn];
bool check(LL a,LL b,LL c){
return (sum[c] - sum[b])*(b - a) <= (sum[b] - sum[a])*(c - b);
}
int main(){
while(~scanf("%d%d",&n,&k)){
for(int i = ; i <= n; ++i){
scanf("%I64d",sum + i);
sum[i] += sum[i-];
}
double ret = ;
hd = tl = ;
for(int i = k; i <= n; ++i){
while(hd + < tl && check(q[tl-],q[tl-],i - k)) --tl;
q[tl++] = i - k;
while(hd + < tl && check(q[hd+],q[hd],i)) ++hd;
ret = max(ret,(sum[i] - sum[q[hd]])*1.0/(i - q[hd]));
}
printf("%.2f\n",ret);
}
return ;
}

BNUOJ 3958 MAX Average Problem的更多相关文章

  1. HDU 2993 MAX Average Problem dp斜率优化

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  2. 数据结构:HDU 2993 MAX Average Problem

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. MAX Average Problem(斜率优化dp)

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. hdu 2993 MAX Average Problem(斜率DP入门题)

    题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...

  5. HDU 2993 MAX Average Problem(斜率优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 Problem Description Consider a simple sequence w ...

  6. HDU 2993 - MAX Average Problem - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 Consider a simple sequence which only contains p ...

  7. HDU 2993 MAX Average Problem(斜率优化DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给定一个长度为n(最长为10^5)的正整数序列,求出连续的最短为k的子序列平均值的最大 ...

  8. hdu2993 MAX Average Problem (斜率dp)

    参考:http://www.cnblogs.com/kuangbin/archive/2012/08/27/2657878.html //#pragma warning (disable: 4786) ...

  9. HDU 2993 MAX Average Problem(斜率DP经典+输入输出外挂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给出n,k,给定一个长度为n的序列,从其中找连续的长度大于等于k的子序列使得子序列中的 ...

随机推荐

  1. luogu 3415 祭坛

    题目大意: 在平面上,有 n 个水晶柱,每个水晶柱可以用一个点表示 如果 4 个水晶柱依次相连可以构成一个四边形,满足其两条对角线分别平行于 x 轴和 y 轴,并且对角线的交点位于四边形内部(不包括边 ...

  2. C# MySql 连接

    1.将MySql.Data.dll引用到你的项目中 右键工程去完成. 2.using MySql.Data;  using MySql.Data.MySqlClient; 3. MySqlConnec ...

  3. 过河 2005年NOIP全国联赛提高组(离散化+dp)

    1105 过河 2005年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description 在河上有一 ...

  4. [App Store Connect帮助]一、 App Store Connect 使用入门(2)登录至 App Store Connect

    请使用您的 Apple ID 登录 App Store Connect.如果您是具有“帐户持有人”职能的用户,请使用您用于加入“Apple 开发者计划”的 Apple ID 登录并添加其他用户至您的 ...

  5. JavaScript Date 日期操作

    在前端工程师的道路上,可能有时候需要与时间来打交道,下面我们来看一下日常对日期的操作,今天我们介绍的是Day.js插件 Day.js 是一个轻量的处理时间和日期的 JavaScript 库,和 Mom ...

  6. Python 线程 的 锁

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA9gAAAG7CAYAAAA41T2sAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjw ...

  7. ACM_寻找第N小序列

    寻找第N小序列 Time Limit: 2000/1000ms (Java/Others) Problem Description: Now our hero finds the door to th ...

  8. 简单入门构建spark1.6.1源码环境

    能有源码的辅助,加上自身的修炼,能起到很好的作用! 对于初学者,不建议,一上来看源码. 下载 http://archive.apache.org/dist/spark/spark-1.6.1/

  9. SharePoint通过IP地址访问

    问题:SP站点通过计算机名称可以访问,但不能通过IP地址访问 解决方案:打开SharePoint2010管理中心>应用程序管理>配置备用访问映射>编辑公用 URL 备用访问映射集:选 ...

  10. 利用js写全选操作

    <script type="text/javascript"> function checkall(qx) { var ck=document.getElementsB ...