USACO Sabotage
洛谷 P2115 [USACO14MAR]破坏Sabotage
https://www.luogu.org/problem/P2115
JDOJ 2418: USACO 2014 Mar Gold 2.Sabotage
https://neooj.com/oldoj/problem.php?id=2418
Description
Problem 2: Sabotage [Brian Dean, 2014]
Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer
John's milking equipment!
FP是FJ的死对头,他想破坏FJ的挤奶系统。
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.
FJ的挤奶系统包含一行共N(3 <= N <= 100,000)个挤奶器,其中第i号挤奶器可以挤M_i(1<= M_i <= 10,000)升牛奶。
FP打算破坏从第i号到第j号这连续的一段挤奶器(2 <=i <= j <= N-1),但保罗不打算破坏第1号和第N号挤奶器。
FP想要达到的目的是使得剩下的挤奶器的平均产量尽可能低。FP至少要破坏一个挤奶器。
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.
求这个最低的平均产量。
Input
* Line 1: The integer N.
* Lines 2..1+N: Line i+1 contains M_i.
Output
* 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
1
7
8
2
Sample Output
HINT
OUTPUT DETAILS:
The optimal solution is to remove the 7 and 8, leaving 5, 1, and 2, whose
average is 8/3.
因为是一段连续的数列,所以自然而然地想到维护一个前缀和数组,并且采用二分答案来优化枚举平均值。
#include<cstdio>
#include<algorithm>
using namespace std;
int sum[];
int n;
bool check(double x)
{
double minv = sum[]-x*;
for(int i=;i<n;i++)
{
if (sum[n]-x*n-(sum[i]-x*i)+minv<=)
return ;
minv=min(minv,sum[i]-x*i);
}
return ;
}
int main()
{
scanf("%d",&n);
for (int i=; i<=n; i++)
{
int a;
scanf("%d",&a);
sum[i] = sum[i-]+a;
}
double l = , r = ;
while(r-l>1e-)
{
double mid = (l+r)/;
if (check(mid))
r = mid;
else
l = mid;
}
printf("%.3lf",r);
return ;
}
USACO Sabotage的更多相关文章
- USACO Sabotage, 2014 Mar 破坏阴谋(二分+贪心)
一开始看完这题就有个想法: 只要把大于整个序列平均数的最大连续序列就是最优? 那把整个序列都减掉平均数 在做最大连续字序列和且记录长度? 仔细思考一下并不太对: 当子序列最大但长度较大 也许也比不上删 ...
- USACO翻译:USACO 2014 MARCH GOLD P2 Sabotage
1.破坏{DOLD题2} sabotage.pas/c/cpp [问题描述] 农夫约翰的头号敌人保罗决定破坏农民约翰的挤奶设备.挤奶设备排成一行,共N(3<= N <=100000)台挤奶 ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- 【USACO 3.1】Stamps (完全背包)
题意:给你n种价值不同的邮票,最大的不超过10000元,一次最多贴k张,求1到多少都能被表示出来?n≤50,k≤200. 题解:dp[i]表示i元最少可以用几张邮票表示,那么对于价值a的邮票,可以推出 ...
- USACO翻译:USACO 2013 NOV Silver三题
USACO 2013 NOV SILVER 一.题目概览 中文题目名称 未有的奶牛 拥挤的奶牛 弹簧牛 英文题目名称 nocow crowded pogocow 可执行文件名 nocow crowde ...
- USACO翻译:USACO 2013 DEC Silver三题
USACO 2013 DEC SILVER 一.题目概览 中文题目名称 挤奶调度 农场航线 贝西洗牌 英文题目名称 msched vacation shuffle 可执行文件名 msched vaca ...
- USACO翻译:USACO 2014 DEC Silver三题
USACO 2014 DEC SILVER 一.题目概览 中文题目名称 回程 马拉松 奶牛慢跑 英文题目名称 piggyback marathon cowjog 可执行文件名 piggyback ma ...
- USACO翻译:USACO 2012 FEB Silver三题
USACO 2012 FEB SILVER 一.题目概览 中文题目名称 矩形草地 奶牛IDs 搬家 英文题目名称 planting cowids relocate 可执行文件名 planting co ...
- USACO翻译:USACO 2012 JAN三题(3)
USACO 2012JAN(题目三) 一.题目概览 中文题目名称 放牧 登山 奶牛排队 英文题目名称 grazing climb lineup 可执行文件名 grazing climb lineup ...
随机推荐
- jdk 自带命令行工具
jps工具 虚拟机进程状况工具 工具主要选项 jstat: 虚拟机统计信息监视工具 jinfo: Java配置信息工具 jinfo( Configuration Info for Java) 的作用是 ...
- Vue 变异方法sort&reverse对评论进行排序
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- finalize()方法什么时候被调用?析构函数(finalization)的目的是什么?
链接:https://www.nowcoder.com/questionTerminal/d8eab06913084e42b515633604eef7cd?pos=28&mutiTagIds= ...
- 【mysql】修改mysql数据库密码
修改mysql数据库密码 操作系统:Linux centos7 数据库:mysql5.7 一.在已知MYSQL数据库的ROOT用户密码的情况下,修改密码 1.在Linux命令行,使用mysqladmi ...
- HDU-1719 Friend 数学推导
Friend HDU - 1719 Friend number are defined recursively as follows. (1) numbers 1 and 2 are friend n ...
- powershell与linux bash对比
转自Github/Powershell Bash PowerShell Description ls dir, Get-ChildItem List files and folders tree di ...
- MS14-068域提权漏洞复现
MS14-068域提权漏洞复现 一.漏洞说明 改漏洞可能允许攻击者将未经授权的域用户账户的权限,提权到域管理员的权限. 微软官方解释: https://docs.microsoft.com/zh-cn ...
- WPF两个按钮来回切换样式
<!-- 两个按钮来回切换样式 --> <Style x:Key="SwicthFunctionMetroToggleButton" TargetType=&qu ...
- Winform 美化
首先,我们先来实现主界面的扁平化 此处分为两个步骤,第一步是更改winform自带的MainForm窗体属性,第二步是添加窗体事件. 将主窗体FormBorderStyle更改为None,这样就得到了 ...
- 纯 JS 设置文本框的默认提示
HTML5 中有个新特性叫 placeholder,一般用它来描述输入字段的预期值,适用于 text.search.password 等类型的 input 以及 textarea.示例如下: < ...