[Usaco2014 Mar]Sabotage

题目

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 台机器,第 i 台机器的工作能力为 Ai。保罗阴谋破坏一些机器,使得约翰的
工作效率变低。保罗可以任意选取一段编号连续的机器,使它们停止工作。但这样的破坏只能搞一次,
而且保罗无法破坏第一台或最后一台机器。请问他该破坏哪些机器才能让剩下机器的工作效率的平均
数最小?为了显示存在感,保罗至少必须破坏一台机器。

INPUT

Line 1: The integer N.

Lines 2..1+N: Line i+1 contains M_i.

OUTOUT

Line 1: The lowest possible average Farmer Paul can achieve, rounded to 3 digits after the decimal point, and printed with 3 digits after the decimal point.

SAMPLE

INPUT

5

5

1

7

8

2

OUTPUT

2.667

解题报告

实数二分的力量= =

我们二分答案,得到最小的平均值,然后验证该平均值是否合法

重点就落到如何验证了

设当前验证的平均值为$avr$

那么对于$a_{i}$来说,存在$b_{i}=a_{i}-avr$,那么,当$b_{i}>0$时,$a_{i}>avr$,$b_{i}<0$时,$a_{i}<avr$

那么,对于每一个$avr$,我们可以处理出来这个$b$数组

我们考虑,既然我们只能去掉一段连续的区间,那么剩下的也一定是两个连续区间

所以,我们可以处理出来每个点的前缀和与后缀和的最小值,(这里的最小值是指,在前(后)缀不断更新时,更新该点之前的历史最小值),然后我们判断,是否存在一点,使其前缀和最小值与后缀和最小值的和$sum$满足$sum<=0$,这样,显然就一定存在一个包含该点的区间,其左端点的前缀和与后缀和之和$tot$满足$tot<=0$,这两个和即分别为两端区间的区间和

既然存在了这样的处于两端的两个区间,那么就存在这两个区间的平均值小于该平均值

即:该平均值合法

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 using namespace std;
 5 inline int read(){
 6     int sum(0);
 7     char ch(getchar());
 8     for(;ch<'0'||ch>'9';ch=getchar());
 9     for(;ch>='0'&&ch<='9';sum=sum*10+(ch^48),ch=getchar());
10     return sum;
11 }
12 int n;
13 double a[100005],sum;
14 double b[100005];
15 const double eps(1e-8);
16 double pre[100005],nxt[100005];
17 inline bool check(double x){//cout<<x<<endl;
18     for(int i=1;i<=n;++i)
19         b[i]=a[i]-x,pre[i]=nxt[i]=1e16;/*,cout<<i<<' '<<b[i]<<' ';cout<<endl;*/
20     double sum(0),mn(1e16);
21     for(int i=1;i<=n;++i)
22         pre[i]=min(sum,mn),sum+=b[i],mn=min(mn,sum);
23     sum=0,mn=1e16;
24     for(int i=n;i>0;--i)
25         nxt[i]=min(sum,mn),sum+=b[i],mn=min(mn,sum);
26     for(int i=2;i<n;++i)
27         if(pre[i]+nxt[i]<=eps)
28             return true;
29     return false;
30 }
31 int main(){
32     n=read();
33     for(int i=1;i<=n;++i)
34         a[i]=read(),sum+=a[i];
35     double l(0),r(sum),ans;
36     while(r-l>=eps){
37         double mid((l+r)/2.0);//cout<<l<<' '<<r<<' '<<mid<<endl;
38         if(check(mid))
39             r=mid,ans=mid;
40         else
41             l=mid;
42     }
43     printf("%.3lf",ans);
44 }

View Code

转载于:https://www.cnblogs.com/hzoi-mafia/p/7517823.html

[Usaco2014 Mar]Sabotage相关推荐

  1. 二分答案 [Usaco2014 Mar]Sabotage

    问题 L: [Usaco2014 Mar]Sabotage 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Farmer John"s arch-nemesis, Farmer ...

  2. BZOJ 3479: [Usaco2014 Mar]Watering the Fields( MST )

    MST...一开始没注意-1结果就WA了... ---------------------------------------------------------------------------- ...

  3. BZOJ3476 : [Usaco2014 Mar]The Lazy Cow

    旋转坐标系后转化为正方形,$x'=x+y$,$y'=x-y+1000001$,$k'=2k-1$ 两根扫描线从左往右扫 f[i]表示y坐标下边界为i时的价值和 每次加入/删除一个点等价于一段区间加减 ...

  4. USACO Sabotage

    洛谷 P2115 [USACO14MAR]破坏Sabotage https://www.luogu.org/problem/P2115 JDOJ 2418: USACO 2014 Mar Gold 2 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买( dp + 斜率优化 )

    既然每块都要买, 那么一块土地被另一块包含就可以不考虑. 先按长排序, 去掉不考虑的土地, 剩下的土地长x递增, 宽y递减 dp(v) = min{ dp(p)+xv*yp+1 } 假设dp(v)由i ...

  6. JSOI2012-夏令营 Mar Maps

    火星探险 源程序名 MAR.??? (PAS,C,CPP) 输入文件名 MAR.IN 输出文件名     MAR.OUT 时间限制      1S 问题描述: 在2051年,若干火星探险队探索了这颗红 ...

  7. 5GS 协议栈 — PFCP 协议 — MAR 多接入规则

    目录 文章目录 目录 MAR 多接入规则 MAR 的参数 MAR 多接入规则 MAR 的参数 N4 Session ID:Identifies the N4 session associated to ...

  8. 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: ...

  9. 动态规划 BZOJ1584 [Usaco2009 Mar] Cleaning Up 打扫卫生

    1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec  Memory Limit: 64 MB Submit: 511  Solved: 3 ...

最新文章

  1. 完整的Python 3和树莓Pi大师课 Complete Python 3 and Raspberry Pi Masterclass
  2. python二维数组怎么写_python的二维数组操作
  3. linux防火墙怎么添加端口,手工添加Linux防火墙端口
  4. Sublime Text3 如何安装、删除及更新插件
  5. Adobe Acrobat Reader快捷键
  6. 静态路由(原理+实验)
  7. static和不完全类型的一个例子
  8. 小米9android q测试版,基于Android Q的MIUI来了 小米9尝鲜
  9. 【ArcGIS|3D分析】要素的立体显示
  10. ubuntu/centos Server 安装完成后,开启SSH,配置IP地址,DNS
  11. python excel对比_Python处理Excel模块的对比分析
  12. NUVOTON的IAP SFR
  13. ABAP对excel的操作(合并单元格,设置边框)
  14. Java Web基础性知识
  15. C语言坐标旋转,c语言矩阵的顺、逆时针旋转
  16. 程序员辛酸泪——当程序员老去,程序员又何去何从
  17. javascript考勤日历
  18. 聚宝匯wap站测试工具版本号
  19. Windows系统解决谷歌翻译不能用的问题
  20. 是面试官放水,还是公司实在是太缺人?这都没挂,字节原来这么容易进...

热门文章

  1. 蓬莱小课:一线城市数据分析师岗位薪酬有多少?
  2. 【悲观锁与乐观锁的原理及实现】
  3. 麒麟子Cocos Creator 3D研究笔记八:3D坐标转2D人物血条
  4. mac m2 编译dubbo3.1.x版本报Missing:com.google.protobuf:protoc:exe:osx-aarch_64
  5. OSX app (Mac app) crash 文件分析与定位
  6. android ondestroy service,onDestroy在android中运行时,MainActivity泄露了ServiceConnection。如何防止这个错误?...
  7. 中国内地首家美高梅品牌城市酒店开业;斯凯孚集团现任CEO首度访华 | 美通企业日报...
  8. linux中修改硬盘分区的卷标
  9. 珂朵莉树(odt老司机树)
  10. QString 转换 Wchar_t方法比对