洛谷【P2115】[USACO14MAR]破坏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 &…
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 machi…
题意:给你一个正整数序列,让你删去一段区间内的数[l,r] $1<l\le r <n$ 使得剩余的数平均值最小$n\le 10^5$ 1.不难想到暴力,用前缀和优化$O(n^2)$ #include<cstdio> #include<iostream> #include<cstring> #include<cctype> #include<algorithm> #include<cmath> using namespace…
我对二分的理解:https://www.cnblogs.com/AKMer/p/9737477.html 题目传送门:https://www.luogu.org/problemnew/show/P2115 对于我们要求的一个"最小平均值",我们可以通过二分来得到.对于我们二分的那个平均值,我们令每一个数全部减去它,然后这时删掉"最大子段和"就是最优策略. 假设减完平均值之后的数列和为\(sum\),那么我们二分的平均值为\(ave\),要使得平均值降到\(ave\)…
题目 [USACO14MAR]Sabotage G 题解 本蒟蒻又来了,这道题可以用二分答案来解决.我们可以设答案最小平均产奶量为 \(x \ (x \in[1,10000])\) .然后二分搜索 \(x\) 的最小值. \[\frac{sum-sum[l,r]}{n-(r-l+1)}\leq x \] \[nx-(r-l+1)x\geq sum-sum[l,r] \] \[sum-nx \leq \sum\limits_{i=l}^r{(a[i]-x)} \] 对于如何求 \(\sum\lim…
题目描述 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 &…
本来是想找一道生成树的题做的...结果被洛咕的标签骗到了这题...结果是二分答案与生成树一点mao关系都没有.... 题目大意:给你一个序列,请你删去某一个$l~r$区间的值($2<=i<=j<=n-1$),使得剩余元素的平均值最小. 开始是想二分序列长度的,后来发现没什么卵用...于是再想一想二分平均值,但是又感觉并没有二分单调性...(其实是满足的,因为我们二分出的最终答案,当比这个答案大的时候,我们一定能满足,小的时候一定不能满足.) 因为二分的复杂度带了一个$log$,所以我们$…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
P2212 [USACO14MAR]浇地Watering the Fields 题目描述 Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1 <= N <= 2000). Each field i is described by a distinct point (xi, yi) in the 2D plane, with 0 &…
还是二分答案,发现我的$check$函数不太一样,来水一发题解 列一下式子 $$\frac{sum-sum[l,r]}{n-(r-l+1)}<=ans$$ 乘过去 $$sum-sum[l,r]<=ans*(n-r+l-1)$$ 即 $$\sum_{i=1}^{l-1}+\sum_{i=r+1}^{n}<=ans*(n-r+l-1)$$ $$\sum{(a_i-ans)}<=0$$ 所以我们在$check$函数中,可以处理出$a_i-ans$数组 然后求个前缀和,后缀和,前缀最小值,…