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的子序列使得子序列中的 ...
随机推荐
- ASP.NET SignalR Hubs API Guide - JavaScript Client
https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-javascript- ...
- 39. Ext.data.SimpleStore的使用方法
转自:https://www.cnblogs.com/bluestorm/archive/2013/06/14/3135361.html 新版4.2的extjs已经废弃了simpleStore --& ...
- Spring IOC set注入
Hobby.java package com.wh.bean; public class Hobby { private Integer id; private String name; public ...
- [转]mysql的约束
转自:http://blog.csdn.net/kqygww/article/details/8882990 MySQL中约束保存在information_schema数据库的table_constr ...
- 元素属性的添加删除(原生js)
添加属性 odiv.setAttribute("title","hello div!"); odiv.setAttribute("class" ...
- iOS 从xib中加载自定义视图
想当初在学校主攻的是.NET,来到公司后,立马变成java开发,之后又跳到iOS开发,IT人这样真的好么~~ 天有不测风云,云还有变幻莫测哎,废话Over,let's go~ 新学iOS开发不久,一 ...
- C#入门经典 Chapter3 变量和表达式
3.1 C#基本语法 分号结束语句 花括号字符不需要附带分号 缩进 注释:/*....*/,//,/// 区分大小写 3.2 C#控制台应用程序的基本结构 namespace Chapter3 ...
- html——表单控件
基本的表单控件还有html5的一些新的表单控件: <!DOCTYPE html> <html> <head> <meta charset="utf- ...
- Linux 查询PID和端口号
https://www.cnblogs.com/understander/p/5546458.html
- 【sqli-labs】 less58 GET -Challenge -Double Query -5 queries allowed -Variation1 (GET型 挑战 双查询 只允许5次查询 变化1)
单引号闭合成功,但是union select结果不对 http://192.168.136.128/sqli-labs-master/Less-58/?id=0' union select 1,2,3 ...