Best Cow Fences

二分答案 + 前缀和

个人认为题意没有表述清楚,本题要求的是满足题意的连续子序列(难度大大降低了有木有)。

本题的精度也是非常令人陶醉,请您自行体会吧!

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
//Mystery_Sky
//
#define M 10000100
#define ex 1e-5
double l = 100000.0, r = -10000.0, mid;
int n, L;
double a[M], sum[M];
inline bool check(double ans)
{
double sum1, sum2, maxx;
sum1 = sum[L-1] - (L-1) * ans;
for(int i = L; i <= n; i++) {
sum2 = sum[i] - sum[i - L] - L * ans;
sum1 = sum1 + a[i] - ans;
sum1 = max(sum1, sum2);
if(sum1 > -ex) return true;
}
return false;
} int main() {
scanf("%d%d", &n, &L);
for(int i = 1; i <= n; i++) {
scanf("%lf", &a[i]);
sum[i] = sum[i-1] + a[i];
l = min(l, a[i]), r = max(r, a[i]);
}
while(r - l > ex) {
mid = (l + r)/2;
if(check(mid)) l = mid;
else r = mid;
}
int ans = (int)(r * 1000);
printf("%d", ans);
return 0;
}

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

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

    1434:[例题2]Best Cow Fences 时间限制: 1000 ms         内存限制: 65536 KB提交数: 263     通过数: 146 [题目描述] 给定一个长度为n的 ...

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

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

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

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

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

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

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

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

  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. ubuntu16.04 ROS安转及RVIZ启动

    1.软件中心配置 首先打开软件和更新对话框,打开后按照下图进行配置(确保你的"restricted", "universe," 和 "multiver ...

  2. MFC绘制直角坐标系

    void CMyPicoTestDlg::DrawWave(CDC *pDC,CRect &rectPicture) { CPen newPen; //用于创建新画笔 CPen *pOldPe ...

  3. dumpbin检查Dll

    用dumpbin.exe工具查看DLL,dumpbin.exe是VS自带的工具.版本VS2013,路径是:G:\VS2013\VC\bin\amd64\ 可以看到dumpbin.exe. 使用VS里的 ...

  4. sort()的升降序函数操作

    sort()函数包含在头文件#include <algorithm>中,是常用的排序函数. functional提供了一堆基于模板的比较函数对象.它们是:equal_to<Type& ...

  5. ECharts使用问题

    Echarts官网上给的例子,在最后有一个分号. 使用ajax请求,在eval()转化时出现错误,原因就是因为多了一个分号

  6. HDU1010 Tempter of the Bone【小狗是否能逃生----DFS奇偶剪枝(t时刻恰好到达)】

    Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  7. C#总结---方法的out参数和ref参数

    我们知道,在c#中,当我们在一个方法中想要访问另一个方法中的变量的时候,有两种解决方案---参数和返回值.但当需要返回多个值,并且是不同类型的值的之后应该怎么办呢?解决方案可以是 (1)将所有类型数据 ...

  8. lightoj 1027【数学概率】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=1e2+10; int ma ...

  9. unity 在移动平台中,文件操作路径详解

    今天,这篇文章其实是个老生常谈的问题咯,在网上类似的文章也比比皆是,在此我只是做个详细总结方便大家能够更好.更快的掌握,当然,如有不足的地方 欢迎指正!!! 相信大家在开发过程中,难免会保存一些文件在 ...

  10. 51nod1770(xjb)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1770 题意:中文题诶- 思路:随便写几个例子不难发现乘机中间部 ...