BNUOJ 3958 MAX Average Problem
MAX Average Problem
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
#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的更多相关文章
- HDU 2993 MAX Average Problem dp斜率优化
MAX Average Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- 数据结构:HDU 2993 MAX Average Problem
MAX Average Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- MAX Average Problem(斜率优化dp)
MAX Average Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- hdu 2993 MAX Average Problem(斜率DP入门题)
题目链接:hdu 2993 MAX Average Problem 题意: 给一个长度为 n 的序列,找出长度 >= k 的平均值最大的连续子序列. 题解: 这题是论文的原题,请参照2004集训 ...
- HDU 2993 MAX Average Problem(斜率优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 Problem Description Consider a simple sequence w ...
- HDU 2993 - MAX Average Problem - [斜率DP]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 Consider a simple sequence which only contains p ...
- HDU 2993 MAX Average Problem(斜率优化DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给定一个长度为n(最长为10^5)的正整数序列,求出连续的最短为k的子序列平均值的最大 ...
- hdu2993 MAX Average Problem (斜率dp)
参考:http://www.cnblogs.com/kuangbin/archive/2012/08/27/2657878.html //#pragma warning (disable: 4786) ...
- HDU 2993 MAX Average Problem(斜率DP经典+输入输出外挂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给出n,k,给定一个长度为n的序列,从其中找连续的长度大于等于k的子序列使得子序列中的 ...
随机推荐
- sql 语句NVL()用法
一NVL函数是一个空值转换函数 NVL(表达式1,表达式2) 如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值. 该函数的目的是把一个空值(null)转换成一个实际的值.其表达式的 ...
- SmartDispatcher 类
UI线程中使用 public class SmartDispatcher { public static void BeginInvoke(Action action) { if (Deploymen ...
- 68. 对Extjs中store的多种操作
转自:https://www.cnblogs.com/exmyth/archive/2013/05/16/3082045.html 先来个声明,看着不错,贴过来的,没都测试过. Store.getCo ...
- Hyper-v 3.0 安装centos6.3
Hyper-v 3.0 安装centos6.3 我们说到hyper-v3.0就想到了windows8.windows2012:我们也知道在windows8.windows2012上安装centos系统 ...
- Linux系统的整体目录结构和文件解析
Linux系统目录结构 使用 ls / 查看系统的文件目录: /:根目录,根目录下一般只存放子目录,不存放文件.在linux系统中所有的文件都挂载该目录下. /bin:命令目录. 存放系统的可执行的二 ...
- maven的pom.xml文件错误
来自:http://www.cnblogs.com/shihujiang/p/3492864.html
- null, undefined,"",0,false是什么关系?
null本质上和0,"",false是一类东西,它们都表示一种数据类型的非值.正如0表示数字类型的非值,""表示字符类型的非值一样,null表示完全空的对象,即 ...
- [Swift通天遁地]四、网络和线程-(9)上传图片并实时显示上传进度
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]五、高级扩展-(3)日期和时间类型的扩展方法
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- 写出更好的 JavaScript 条件语句
1. 使用 Array.includes 来处理多重条件 // 条件语句 function test(fruit) { if (fruit == 'apple' || fruit == 'strawb ...