先二分答案m, 然后对于原序列 A[i] = A[i] - m,  然后O(n)找最大连续子序列和, 那么此时序列由 L + mx + R组成. L + mx + R = sum - n * m, sum为原序列的和.

假如二分的答案m是可行的, 那么 L + R = sum - n * m - mx 应该 <= 0

-------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
  
#define rep(i, n) for(int i = 0; i < n; i++)
#define clr(x, c) memset(x, c, sizeof(x))
  
using namespace std;
 
const int maxn = 100009;
const double eps = 1e-3;
 
int A[maxn], n, sum;
double B[maxn], T[maxn];
 
bool check(double m) {
double p = 0, B, mx = -1e10;
for(int i = 1; i < n - 1; i++) {
B = A[i] - m;
if(p >= 0) B += p;
mx = max(mx, p = B);
}
return sum - n * m - mx <= 0;
}
 
int main() {
freopen("test.in", "r", stdin);
cin >> n;
sum = 0;
rep(i, n) {
   scanf("%d", A + i);
   sum += A[i];
}
double L = 1, R = 10000;
while(R - L >= eps) {
double m = L + (R - L) / 2;
check(m) ? R = m : L = m;
}
printf("%.3lf\n", (L + R) / 2);
return 0;
}

-------------------------------------------------------------------------------------

3477: [Usaco2014 Mar]Sabotage

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 106  Solved: 61
[Submit][Status][Discuss]

Description

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.

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
5
1
7
8
2

Sample Output

2.667
OUTPUT DETAILS: The optimal solution is to remove the 7 and 8, leaving 5, 1, and 2, whose average is 8/3.

HINT

Source

BZOJ 3477: [Usaco2014 Mar]Sabotage( 二分答案 )的更多相关文章

  1. BZOJ_3477_[Usaco2014 Mar]Sabotage_二分答案

    BZOJ_3477_[Usaco2014 Mar]Sabotage_二分答案 题意: 约翰的牧场里有 N 台机器,第 i 台机器的工作能力为 Ai.保罗阴谋破坏一些机器,使得约翰的工作效率变低.保罗可 ...

  2. 【bzoj】3477: [Usaco2014 Mar]Sabotage 01分数规划

    这题算是01分数规划吧2333 sum-a[i]*x[i]=c*(n-x[i]) 化简一下就是sum-(a[i]-c)*x[i]-nc=0,每次找最大的(a[i]-c)*x[i](子段和),如果结果& ...

  3. [Usaco2014 Mar]Sabotage

    [Usaco2014 Mar]Sabotage 题目 Farmer John"s arch-nemesis, Farmer Paul, has decided to sabotage Far ...

  4. [USACO14MAR] Sabotage 二分答案 分数规划

    [USACO14MAR] Sabotage 二分答案 分数规划 最终答案的式子: \[ \frac{sum-sum[l,r]}{n-len[l,r]}\le ans \] 转换一下: \[ sum[1 ...

  5. [BZOJ 1816] [Cqoi2010] 扑克牌 【二分答案】

    题目链接:BZOJ - 1816 题目分析 答案具有可以二分的性质,所以可以二分答案. 验证一个答案 x 是否可行,就累加一下各种牌相对于 x 还缺少的量,如果总和超过了 x 或 m ,就不可行. 因 ...

  6. [USACO14MAR]破坏Sabotage 二分答案

    题目描述 Farmer John's arch-nemesis, Farmer Paul, has decided to sabotage Farmer John's milking equipmen ...

  7. [BZOJ 1816][Cqoi2010]扑克牌(二分答案)

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1816 分析: 我先以为是道水题,但是要注意的是每套牌中Joker只能用1张的,所以就出现了可能 ...

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

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

  9. BZOJ 1044: [HAOI2008]木棍分割(二分答案 + dp)

    第一问可以二分答案,然后贪心来判断. 第二问dp, dp[i][j] = sigma(dp[k][j - 1]) (1 <= k <i, sum[i] - sum[k] <= ans ...

随机推荐

  1. Android 中文API (66) —— BluetoothClass.Device

    前言 本章内容是android.bluetooth.BluetoothClass.Device,为Android蓝牙部分的章节翻译,版本为Android 2.3   r1,翻译来自中山大学的" ...

  2. map的erase()释放内存

    STL中的map调用erase(it),当value值为指针时,释放内存: #include <iostream> #include <map> #include <st ...

  3. jQ 操作积累

    1.判断radio是否选中:方式一:var val=$('input:radio[name="sex"]:checked').val(); //(val==null 未选中) 方式 ...

  4. 文件下载 .net

    protected void Button1_Click(object sender, EventArgs e)  { /* 微软为Response对象提供了一个新的方法TransmitFile来解决 ...

  5. MAVEN入门(二)

    一.IDEA+MAVEN+Tomcat7 创建一个简单的Web app 1.用IDEA创建一个maven项目 注意: 红色部分一定要自己手选本地配置好的maven_home的地址,否则IDEA会选用内 ...

  6. 高级UNIX环境编程5 标准IO库

    标准IO库都围绕流进进行的 <stdio.h><wchar.h> memccpy 一般用汇编写的 ftell/fseek/ftello/fseeko/fgetpos/fsetp ...

  7. jQuery.form 中的 ajaxForm() 和 ajaxSubmit()

    官方例子  http://malsup.com/jquery/form/#ajaxForm官方API   http://malsup.com/jquery/form/#api中文API   http: ...

  8. 学校作业-Usaco DP水题

    好吧,因为USACO挂掉了,所以我写的所有代码都不保证正确性[好的,这么简单的题,再不写对,你就可以滚粗了! 第一题是USACO 2.2.2 ★Subset Sums 集合  对于从 1 到 N 的连 ...

  9. HDU 4642 (13.08.25)

    Fliping game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  10. ThinkPHP - 图片水印

    图片添加水印 可以通过使用Image类的水印方法给图片添加水印支持,例如:water 给图片添加水印 用法   water($source, $water, $savename=null, $alph ...