1434:【例题2】Best Cow Fences

时间限制: 1000 ms         内存限制: 65536 KB
提交数: 263     通过数: 146

【题目描述】

给定一个长度为n的正整数序列A。求一个平均数最大的,长度不小于L的子序列。

【输入】

第一行,n和L;

n个正整数,表示A。

【输出】

一个整数,表示答案的1000倍(不用四舍五入,直接输出)。

【输入样例】

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

【输出样例】

6500

【提示】

n ≤ 10000

思路::

问题转化
1.是否存在一个长度不小于L的子段,子段序列和为非负。及二分查找
2.子段序列和可以是后段减前段
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double a[],b[],sum[];
int main(){
int N,L;
cin>>N>>L;
for(int i=;i<=N;i++){
cin>>a[i];
}
double eps=1e-;
double l=-1e-,r=1e6;
while(r-l>eps){//二分答案
double mid=(l+r)/;
for(int i=;i<=N;i++) b[i]=a[i]-mid;
for(int i=;i<=N;i++) sum[i]=(sum[i-]+b[i]);
double ans=-1e10;
double minn=1e10;
for(int i=L;i<=N;i++){
minn=min(minn,sum[i-L]);
ans=max(ans,sum[i]-minn);
//前缀和相减
}
if(ans>=) l=mid;
else r=mid;
}
cout<<int(r*)<<endl;
return ;
}

1434:【例题2】Best Cow Fences的更多相关文章

  1. 一本通 1434:【例题2】Best Cow Fences

    Best Cow Fences 二分答案 + 前缀和 个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有). 本题的精度也是非常令人陶醉,请您自行体会吧! #includ ...

  2. POJ 2018 Best Cow Fences(二分+最大连续子段和)

    Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14601 Accepted: 4720 Desc ...

  3. POJ-2018 Best Cow Fences(二分加DP)

    Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10174 Accepted: 3294 Desc ...

  4. POJ2018 Best Cow Fences —— 斜率优化DP

    题目链接:https://vjudge.net/problem/POJ-2018 Best Cow Fences Time Limit: 1000MS   Memory Limit: 30000K T ...

  5. loj#10012\poj2018 Best Cow Fences(二分)

    题目 #10012 「一本通 1.2 例 2」Best Cow Fences 解析 有序列\(\{a_i\}\),设\([l,r]\)上的平均值为\(\bar{x}\),有\(\sum_{i=l}^r ...

  6. Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)

    Best Cow Fences Time Limit: 1000MS Memory Limit: 30000K Description Farmer John's farm consists of a ...

  7. POJ 2018 Best Cow Fences (二分答案构造新权值 or 斜率优化)

    $ POJ~2018~Best~Cow~ Fences $(二分答案构造新权值) $ solution: $ 题目大意: 给定正整数数列 $ A $ ,求一个平均数最大的长度不小于 $ L $ 的子段 ...

  8. 题解0002:Best Cow Fences

    题目描述:给定一个长度为n的正整数序列A.求一个平均数最大的,长度不小于L的子序列,输出这个平均数*1000. 题目链接:http://ybt.ssoier.cn:8088/problem_show. ...

  9. [USACO2003][poj2018]Best Cow Fences(数形结合+单调队列维护)

    http://poj.org/problem?id=2018 此乃神题……详见04年集训队论文周源的,看了这个对斜率优化dp的理解也会好些. 分析: 我们要求的是{S[j]-s[i-1]}/{j-(i ...

随机推荐

  1. 三角函数补充(反三角函数与 sec)

    1. sec=1cos Secant (sec) - Trigonometry function secx=HA

  2. uwsgi 配置 初试

    /************************************************************************************** * uwsgi 配置 初 ...

  3. softmax regression in c++

    #include <iostream>#include <vector>#include <cmath>#include <algorithm>#inc ...

  4. js函数定义 参数只要写名称就可以了

    js函数定义  参数只要写名称就可以了 以下为标准: function add(type)  { } 不要写成下面这个样子 function add(var type)  { } 哎 妹的  老何ja ...

  5. 配置DTD提示的方法

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE sqlMap PUBLIC "-/ ...

  6. MD5 密码加密算法 系统等待

    MD5 密码加密算法 public static String md(String md, String pass) { MessageDigest m; String passok = " ...

  7. LUR和缺页次数

    缺页:缺页中断就是要访问的页不在主存,需要操作系统将其调入主存后再进行访问. LRU(Least recently used)算法根据数据的历史访问记录来进行淘汰数据,其核心思想是“如果数据最近被访问 ...

  8. Poj 3189 Steady Cow Assignment (多重匹配)

    题目链接: Poj 3189 Steady Cow Assignment 题目描述: 有n头奶牛,m个棚,每个奶牛对每个棚都有一个喜爱程度.当然啦,棚子也是有脾气的,并不是奶牛想住进来就住进来,超出棚 ...

  9. 解题报告:hdu 1073 Online Judge

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1073 Problem Description Ignatius is building an Onli ...

  10. Service官方教程(2)*IntentService与Service示例、onStartCommand()3个返回值的含义。

    1.Creating a Started Service A started service is one that another component starts by calling start ...