Codeforces 460C Present(二分)
2014-08-25 00:07
423 查看
题目链接:Codeforces 460C Present
题目大意:有n盆花,可以浇m次水,每次浇水的范围为w,被浇到水的花长高1米,问说可以使最矮的花的最高值是多少
解题思路:二分答案,遍历判断一遍。
题目大意:有n盆花,可以浇m次水,每次浇水的范围为w,被浇到水的花长高1米,问说可以使最矮的花的最高值是多少
解题思路:二分答案,遍历判断一遍。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 1e5+5; const int inf = 1e9+maxn; int N, M, W, arr[maxn], v[maxn]; bool judge (int k) { int ti = M, n = 0; memset(v, 0, sizeof(v)); for (int i = 1; i <= N; i++) { n += v[i]; int tmp = max(k - arr[i] - n, 0); ti -= tmp; if (ti < 0) return false; if (i + 1 <= N) v[i+1] += tmp; if (i + W <= N) v[i+W] -= tmp; } return true; } int bsearch (int l, int r) { for (int i = 0; i < 80; i++) { int mid = (r + l) / 2; if (judge(mid)) l = mid; else r = mid; } return l; } int main () { scanf("%d%d%d", &N, &M, &W); for (int i = 1; i <= N; i++) scanf("%d", &arr[i]); printf("%d\n", bsearch(1, inf)); return 0; }
相关文章推荐
- CodeForces 460C--- Present(二分+贪心,还有个地方会TLE)
- CodeForces 460C——二分+前缀和—— Present
- Codeforces 460C Present (贪心 + 二分)
- CodeForces 460C--- Present(二分+贪心)
- Codeforces 460C —— Present(二分答案)
- Present - CODEFORCES, 460c 二分 扫描线求和
- Codeforces 460C Present 二分+前缀和
- codeforces 460C - Present 二分加模拟
- Codeforces 460C Present
- codeforces 460 C Present 二分+贪心 最大化最小值问题
- Codefores 460C-Present(二分+贪心)
- Codeforces 460C Present
- Present CodeForces - 460C 二分—答案
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
- Codeforces 460C 二分结果+线段树维护
- codeforces 689D ST表+二分 模板
- codeforces-760-B Frodo and pillows(二分+数学)
- Codeforces 609F Frogs and mosquitoes 二分+简单离散化线段树+Multimap
- [二分答案 2-SAT验证 前后缀优化建图] Codeforces 587D #326 (Div. 1) D. Duff in Mafia