https://www.luogu.org/problem/show?pid=2115

题目描述

Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipment!

The milking equipment consists of a row of N (3 <= N <= 100,000) milking machines, where the ith machine produces M_i units of milk (1 <= M_i <= 10,000). Farmer Paul plans to disconnect a contiguous block of these machines -- from the ith machine up to the jth machine (2 <= i <= j <= N-1); note that Farmer Paul does not want to disconnect either the first or the last machine, since this will make his plot too easy to discover. Farmer Paul's goal is to minimize the average milk production of the remaining machines. Farmer Paul plans to remove at least 1 cow, even if it would be better for him to avoid sabotage entirely.

Fortunately, Farmer John has learned of Farmer Paul's evil plot, and he is wondering how bad his milk production will suffer if the plot succeeds. Please help Farmer John figure out the minimum average milk production of the remaining machines if Farmer Paul does succeed.

农夫约翰的头号敌人保罗决定破坏农民约翰的挤奶设备。挤奶设备排成一行,共N(3<= N <=100000)台挤奶机,其中第i个台挤奶机生产M_i单位(1 <= M_i<=10,000)的牛奶。

保罗计划切断一段连续的挤奶机,从第i台挤奶机到第j台挤奶机(2<= i<= j<= N-1)。注意,他不希望断开第一台或最后一台挤奶机,因为这将会使他的计划太容易被发现。保罗的目标是让其余机器的平均产奶量最小。保罗计划除去至少1台挤奶机。

请计算剩余机器的最小平均产奶量。

输入输出格式

输入格式:

第 1 行:一个整数 N。

第 2 到 N+1 行:第 i+1 行包含一个整数 M_i。

输出格式:

第 1 行: 一个实数, 表示平均牛奶产量的最小值, 保留三位小数 (四舍五入)。

输入输出样例

输入样例#1:

5
5
1
7
8
2
输出样例#1:

2.667

说明

【样例说明】

移去 7 和 8,剩下 5, 1, 2,平均值为 8/3。

【数据规模和约定】

对于 30%的数据,N <= 1,000。

对于 50%的数据,N <= 10,000。

对于 100%的数据,3 <= N <= 100,000,1 <= M_i <= 10,000。

假设删除区间[i,j]

(sum[n]-sum[j]+sum[i-1])/(n-j+i-1)<=ans

即(sum[n]-sum[j]+sum[i-1])-(n-j+i-1)* ans<=0

有一个i,j满足条件就行

sum[n]-n*ans-sum[j]+j*ans+sum[i-1]-(i-1)*ans<=0

二分ans

枚举j

sum[i-1]-(i-1)*ans这一块肯定是越小越好

枚举j的时候顺便记录这一块的最小值

#include<cstdio>
#include<algorithm>
using namespace std;
#define N 100001
#define eps 1e-5
int n,m[N],sum[N];
double minn;
bool check(double k)
{
minn=sum[]-k;
for(int j=;j<n;j++)
{
if(sum[n]-k*n-sum[j]+k*j+minn<=) return true;
minn=min(minn,sum[j]-k*j);
}
return false;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&m[i]),sum[i]=sum[i-]+m[i];
double l=,r=,mid;
while(r-l>eps)
{
mid=(l+r)/;
if(check(mid)) r=mid-eps;
else l=mid+eps;
}
printf("%.3lf",l);
}

最新文章

  1. Implicit and Explicit Multithreading MULTITHREADING AND CHIP MULTIPROCESSORS
  2. asp.net环境搭建
  3. 软件工程(FZU2015)学生博客列表(最终版)
  4. Android中实现圆角矩形及半透明效果。
  5. jquery mobile validation
  6. 修改app名字
  7. Eclipse+maven发布ee项目jar包未发布
  8. ORACLE归档模式和非归档模式的利与弊
  9. FFmpeg详解
  10. JSP内置对象--response对象 (addCookie(),setHeader(),sendRedirect())
  11. java算法 蓝桥杯(题+答案) 方格填数
  12. Attribute注解
  13. Lazyman功能实现
  14. Java压测之四两拨千斤
  15. Python:每日一题006
  16. Git fetch &amp; pull
  17. linux 环境变量字符串的优先顺序
  18. Idea集成Lombok代码注释来精简代码
  19. Xcode 8 修改项目名
  20. Python数据结构与算法(几种排序)

热门文章

  1. Pipeline组Alpha版本发布说明
  2. JavaScript初探系列之日期对象
  3. lintcode-186-最多有多少个点在一条直线上
  4. Linux 路由 学习笔记 之一 相关的数据结构
  5. win7主题/默认账户图片路径
  6. CSS设计指南之CSS三种机制:继承、层叠和特指
  7. 第26天:js-$id函数、焦点事件
  8. hdu2295-Radar
  9. BZOJ 2306 幸福路径(DP)
  10. 【bzoj4720】[NOIP2016]换教室 期望dp