[Codeforces 460C] Present
[题目链接]
https://codeforces.com/contest/460/problem/C
[算法]
二分 + 贪心
要求最小值最大 , 我们不妨二分最小值 , 若一盆花的高度小于二分的值 , 则将这盆花起的w盆花的高度都加一 , 具体实现时可以使用前缀和 + 差分
时间复杂度 : O(NlogV)
[代码]
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ;
const int inf = 2e9; int n , m , w;
int a[MAXN]; template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool check(int mid)
{
int cnt = ;
static int delta[MAXN];
for (int i = ; i <= n; i++) delta[i] = ;
for (int i = ; i <= n; i++)
{
delta[i] += delta[i - ];
while (a[i] + delta[i] < mid)
{
if (++cnt > m) return false;
delta[i]++;
delta[min(i + w,n + )]--;
}
}
return true;
} int main()
{ read(n); read(m); read(w);
int l = inf , r = ;
for (int i = ; i <= n; i++)
{
read(a[i]);
l = min(l,a[i]);
r = max(r,a[i]);
}
r += m;
int ans = l;
while (l <= r)
{
int mid = (l + r) >> ;
if (check(mid))
{
ans = mid;
l = mid + ;
} else r = mid - ;
}
printf("%d\n",ans); return ; }
[Codeforces 460C] Present的更多相关文章
- codeforces 460C. Present 解题报告
题目链接:http://codeforces.com/submissions/ywindysai 题目意思:有 n 朵花,每朵花都有一定的高度(第 i 朵花对应 ai),m 天之后要把这些花送给别人. ...
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...
- codeforces mysterious present 最长上升子序列+倒序打印路径
link:http://codeforces.com/problemset/problem/4/D #include <iostream> #include <cstdio> ...
- Codeforces 585E - Present for Vitalik the Philatelist(简单莫反+狄利克雷前缀和)
Codeforces 题目传送门 & 洛谷题目传送门 一道不算太难的 D1E 罢--虽然我不会做/kk u1s1 似乎这场 Div1 挺水的?F 就是个 AC 自动机板子还被评到了 3k2-- ...
- CF 460C Present 【DP+】主意
给你n高树花.m日,每天连续浇筑w鲜花.一天一次,花长1高度单位 求m天后.最矮的花最高是多少 最大最小问题能够用二分来解 首先我们能够得到全部花的最矮高度即答案的下界,给这个花浇m天即是答案的上界 ...
- Codeforces 585E. Present for Vitalik the Philatelist(容斥)
好题!学习了好多 写法①: 先求出gcd不为1的集合的数量,显然我们可以从大到小枚举计算每种gcd的方案(其实也是容斥),或者可以直接枚举gcd然后容斥(比如最大值是6就用2^cnt[2]-1+3^c ...
- CodeForces - 460C(二分+差分)
题意 https://vjudge.net/problem/CodeForces-460C 一个长度为 n 的序列 a ,你有 m 次操作的机会,每次操作是将其中连续的 w 个元素增加 1 .最大化最 ...
- Codeforces 460C 二分结果+线段树维护
发现最近碰到好多次二分结果的题目,上次多校也是,被我很机智的快速过了,这个思想确实非常不错.在正面求比较难处理的时候,二分结果再判断是否有效往往柳暗花明. 这个题目给定n个数字的序列,可以操作m次,每 ...
- C - Present
C - Present Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- Ubuntu 系统安装(这里用ubuntu 16.04)
一.安装Vmware Workstation 12 选择新建虚拟机- 下一步-安装根据红框部分及说明一步一步进行 点击下一步进行 接下来默认下一步,直到如下图 这里的最大磁盘大小100G.不会直接在本 ...
- c++基础_特殊的数字
#include <iostream> #include <math.h> using namespace std; int main(){ ;i<;i++){ ; )% ...
- LeetCode(59)SPiral Matrix II
题目 Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. F ...
- CODE【VS】 3160 最长公共子串 (后缀数组)
3160 最长公共子串 题目描述 Description 给出两个由小写字母组成的字符串,求它们的最长公共子串的长度. 输入描述 Input Description 读入两个字符串 输出描述 Outp ...
- python后端开发工程师考证试题
python开发工程师考证试题 问答题链接 python开发工程师考证试题 选择题 题目 关于 Python 程序格式框架的描述,以下选项中错误的是 ( A ) A: Python 语言不采用严格的“ ...
- xtu summer individual 6 D - Checkposts
Checkposts Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForces. Orig ...
- POJ-3692Kindergarten,求最大独立集!
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Description In a kindergarten, there ar ...
- POJ 3348 最直接的凸包问题
题目大意: 给定一堆树的点,找到能组合成的最大面积,一个物体占50面积,求最多放多少物体 #include <cstdio> #include <cstring> #inclu ...
- HDU 4465 递推与double的精确性
题目大意不多说了 这里用dp[i][0] 代表取完第一个盒子后第二个盒子剩 i 个的概率,对应期望就是dp[i][0] *i dp[i][1] 就代表取完第二个盒子后第一个盒子剩 i 个的概率 dp[ ...
- bzoj5105 晨跑 数论lcm
“无体育,不清华”.”每天锻炼一小时,健康工作五十年,幸福生活一辈子”在清华,体育运动绝对是同学们生活中 不可或缺的一部分.为了响应学校的号召,模范好学生王队长决定坚持晨跑.不过由于种种原因,每天都早 ...