这是最大化最小值的一类问题,这类问题通常用二分法枚举答案就行了。

二分答案时,先确定答案肯定在哪个区间内。然后二分判断,关键在于怎么判断每次枚举的这个答案行不行。

我是用a[i]数组表示初始时花的高度,b[i]表示要达到当前枚举的答案(即mid的值)需要这朵花再涨多少。这两个数组很好算,关键是一次浇连续的w朵花,如何更新区间(暴力的O(n2)的去更新就超时了)?可以用线段树,但是这道题没有涉及区间查询,就是在一个数组上更新区间,用线段树未免小题大做。那么其实这种更新就用延迟标记的思想(懒操作)就可以O(n)的解决了。具体方法参见这道很裸的题:hdu4970

lazy[]这个标记数组的作用其实就是能记录更新区间到哪里停止.

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
using namespace std;
#define INF 1000000000
#define eps 1e-8
#define pii pair<int,int>
#define LL long long int
const int maxn=;
int n,m,w,a[maxn],b[maxn],lazy[maxn],ans=;
/*lazy[]这个标记数组的作用其实就是能记录更新区间到哪里停止*/
int main()
{
//freopen("in6.txt","r",stdin);
scanf("%d%d%d",&n,&m,&w);
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
int l=,r=maxn+INF,mid;
while(l<=r)
{
memset(lazy,,sizeof(lazy));
mid=(r+l)/;
for(int i=; i<=n; i++) b[i]=max(,mid-a[i]);
int tm=m,x=;
for(int i=;i<=n;i++)//开始浇水
{
x+=lazy[i];//要先看这一步是不是有标记
b[i]-=x;//把前面对影响到当前b[i]的浇水操作浇上
if(b[i]>)//还大于0,那么就必须要从它开始再来一段浇水了
{
tm-=b[i];
if(tm<) break;//天数限制到了
lazy[i+w]-=b[i];
x+=b[i];
}
}
if(tm<) r=mid-;
else
{
ans=mid;
l=mid+;
}
}
printf("%d\n",ans);
}

Codeforces Round #262 (Div. 2)C(二分答案,延迟标记)的更多相关文章

  1. Codeforces Round #389 (Div. 2) 752E(二分答案)

    题目大意 可以理解成有n个木板,可以选取木板将其劈成2半(如果长度是奇数,就切成x和x+1),切完之后还可以再切 然后你要把这n个木板切成更多的木板,然后从中选择k个,使得这k个木板的最小长度尽量大 ...

  2. Codeforces Round #384 (Div. 2) 734E(二分答案+状态压缩DP)

    题目大意 给定一个序列an,序列中只有1~8的8个整数,让你选出一个子序列,满足下列两个要求 1.不同整数出现的次数相差小于等于1 2.子序列中整数分布是连续的,即子序列的整数必须是1,1,1.... ...

  3. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  4. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  5. Codeforces Round #404 (Div. 2) C 二分查找

    Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18)  找到 1) [n<= m] cout<<n; 2) ...

  6. Codeforces Round #262 (Div. 2) C

    题目: C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. Codeforces Round #262 (Div. 2) 二分+贪心

    题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...

  8. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  9. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

随机推荐

  1. ajax发送js类型的数据

    一.如图所示 var ids = [1,2,3,4,5,6,7] $.ajax({ url: requestUrl, type: 'delete', data: JSON.stringify(ids) ...

  2. SpringMVC:学习笔记(4)——处理模型数据

    SpringMVC—处理模型数据 说明 SpringMVC 提供了以下几种途径输出模型数据: – ModelAndView: 处理方法返回值类型为 ModelAndView时, 方法体即可通过该对象添 ...

  3. 异常:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.

    异常:Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} ...

  4. libsvm+eclipse(java)的配置以及开发需要设置的内容

    主要参考博客: 1.eclipse + libsvm-3.12 用SVM实现简单线性分类    cnBlog中的主要介绍如何导入jar包的问题. 2.LIBSVM入门解读   CSDN,主要是对LIB ...

  5. zookeeper部署搭建

    zookeeper教程 1.先在linux系统中安装jdk并配置环境变量,可以参考下面的链接1 2.下载安装zookeeper软件 教程参考: 链接1:http://www.linuxidc.com/ ...

  6. linux基础四----samba&&nginx

    一 samba 1环境配置: a.确保linux下防火墙关闭比或开放共享目录权限 iPtables -F b.确保setlinux关闭:setenforce 0 c.配置iP 2安装软件包:yum i ...

  7. 八、linux优化一

    1.关闭selinux sed –I ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config grep SELINUX=disable ...

  8. 安装使用snmp监控命令

    1.安装snmp windows下载安装https://sourceforge.net/projects/net-snmp/ centos yum install -y net-snmp net-sn ...

  9. Request对象介绍(客户端到服务器)

    1.处理请求和响应的过程request,response,关于request可以从三个方面着手学习.1:如何获取请求头  行  体   2:请求中文处理     3:请求对象的其它常用方法 1.1:r ...

  10. JAVA获取webapp路径

    1.使用ServletContext获取webapp目录 在Servlet中 String path = getServletContext().getRealPath("/"); ...