洛谷2115 [USACO14MAR]破坏Sabotage
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 行: 一个实数, 表示平均牛奶产量的最小值, 保留三位小数 (四舍五入)。
输入输出样例
5
5
1
7
8
2
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);
}
洛谷2115 [USACO14MAR]破坏Sabotage的更多相关文章
- 洛谷P2115 [USACO14MAR]破坏Sabotage
题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipmen ...
- 洛谷【P2115】[USACO14MAR]破坏Sabotage
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.luogu.org/problemnew/show/P21 ...
- [USACO14MAR]破坏Sabotage 二分答案
题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipmen ...
- LuoguP2115 [USACO14MAR]破坏Sabotage【二分答案】By cellur925
本来是想找一道生成树的题做的...结果被洛咕的标签骗到了这题...结果是二分答案与生成树一点mao关系都没有.... 题目大意:给你一个序列,请你删去某一个$l~r$区间的值($2<=i< ...
- 洛谷——P2212 [USACO14MAR]浇地Watering the Fields
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...
- 洛谷 P2212 [USACO14MAR]浇地Watering the Fields 题解
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an ir ...
- [USACO14MAR]破坏Sabotage
还是二分答案,发现我的$check$函数不太一样,来水一发题解 列一下式子 $$\frac{sum-sum[l,r]}{n-(r-l+1)}<=ans$$ 乘过去 $$sum-sum[l,r]& ...
- 洛谷 P2212 [USACO14MAR]浇地Watering the Fields
传送门 题解:计算欧几里得距离,Krusal加入边权大于等于c的边,统计最后树的边权和. 代码: #include<iostream> #include<cstdio> #in ...
- P2115 [USACO14MAR]破坏Sabotage
题意:给你一个正整数序列,让你删去一段区间内的数[l,r] $1<l\le r <n$ 使得剩余的数平均值最小$n\le 10^5$ 1.不难想到暴力,用前缀和优化$O(n^2)$ #in ...
随机推荐
- HDU 4617 Weapon(三维几何)
Problem Description Doctor D. are researching for a horrific weapon. The muzzle of the weapon is a c ...
- Python中的namespace package
在Python 3.3之前,一个目录想被当成package被导入,必须包含__init__.py文件:而在Python 3.3及以后的版本中,__init__.py文件可以不需要,直接使用import ...
- Thunder团队第二周 - Scrum会议5
Scrum会议5 小组名称:Thunder 项目名称:爱阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...
- python学习摘要(4)--列表简单处理
列表打印,访问列表元素 alist = [a,b,c,d,e] print(alist) friends_name = ['alex','bill','castle','dale'] c = 1 wh ...
- TCP系列15—重传—5、Linux中RTO的计算
之前我们介绍的都是协议中给出的RTO计算方法,下面我们看一下linux实现中RTO的计算方法.在linux中维护了srtt.mdev.mdev_max.rttvar.rtt_seq几个状态变量用来计算 ...
- 软工网络15个人作业4-alpha阶段个人总结(201521123059 叶文柠)
一.个人总结 (1) 类别 具体技能和面试问题 现在回答 毕业找工作时 语言 最拿手的计算机语言之一,代码量多少? 感觉自己没有最拿手的语言,而且拿手的在计算机网络这方面的,所以在软件变成这方面的代码 ...
- centos 安装mod_wsgi
如果自定义升级过了python到2.7 #./configure --with-apxs=/usr/sbin/apxs --with-python=/usr/local/python27/bin/py ...
- java 基础--数组--004
1,数组定义格式 String[] aa; String aa[];2,二位数组的定义格式1 String aa[][] = new String[m][n]; String[] aa[] = new ...
- Creator开源游戏、插件、教程、视频汇总
Creator开源游戏.插件.教程.视频汇总 来源 http://forum.cocos.com/t/creator/44782 王哲首席客服 17-03-17 4 史上最全,没有之一. ...
- POJ1990:MooFest——题解
http://poj.org/problem?id=1990 题目大意:定义一对在树轴上的点,每对点产生的值为两点权值最大值*两点距离,求点对值和. 显然n*n复杂度不行,我们需要用树状数组维护两个东 ...