题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4062

题意:

现在在一条 $x$ 轴上玩植物大战僵尸,有 $n$ 个植物,编号为 $1 \sim n$,第 $i$ 个植物的位置在坐标 $i$,成长值为 $a_i$,初始防御值为 $d_i$。

现在有一辆小车从坐标 $0$ 出发,每次浇水操作必须是先走 $1$ 单位长度,然后再进行浇水,植物被浇一次水,防御值 $d_i+=a_i$。

现在知道,小车最多进行 $m$ 次浇水操作,而已知总防御值为 $min{d_1,d_2,d_3,\cdots,d_n}$。求最大的总防御值为多少。

Input

There are multiple test cases. The first line of the input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ ($2 \le n \le 10^5, 0 \le m \le 10^{12}$), indicating the number of plants and the maximum number of steps the robot can take.

The second line contains integers $a_1,a_2, \cdots, a_n$ ($1 \le a_i \le 10^5$), where indicates the growth speed of the -th plant.

It's guaranteed that the sum of in all test cases will not exceed $10^6$.

Output

For each test case output one line containing one integer, indicating the maximum defense value of the garden DreamGrid can get.

Sample Input
2
4 8
3 2 6 6
3 9
10 10 1

Sample Output
6
4

题解:

二分总防御值,对于固定的防御值 $d$,显然花园里的每个植物都要不小于 $d$,因此贪心地从左往右寻找每一个防御值小于 $d$ 的植物,对它和它右侧的植物反复浇水。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+; int n;
ll m;
ll a[maxn],d[maxn]; ll judge(ll k)
{
memset(d,,(n+)*sizeof(ll));
ll cnt=;
for(int i=;i<=n;i++)
{
if(i==n && d[i]>=k) break;
cnt++, d[i]+=a[i];
if(d[i]>=k) continue; ll tmp=(k-d[i])/a[i]+((k-d[i])%a[i]>);
cnt+=*tmp;
d[i]+=tmp*a[i];
d[i+]+=tmp*a[i+];
}
return cnt;
} int main()
{
ios::sync_with_stdio();
cin.tie(); int T;
cin>>T;
while(T--)
{
cin>>n>>m;
ll mn=1e5+;
for(int i=;i<=n;i++) cin>>a[i], mn=min(mn,a[i]); ll l=, r=mn*m;
while(l<r)
{
ll mid=(l+r+)>>;
if(judge(mid)<=m) l=mid;
else r=mid-;
}
cout<<l<<'\n';
}
}

注:

这题的右区间不要直接设成 $1e17$,因为这样当 $a[i]$ 都是小数据的时候 $judge$ 函数里的 $cnt$ 会爆long long。

不妨设成 $a_i$ 最小值的 $m$ 倍,很容易证明最后的答案是不会超过这个值的。

ZOJ 4062 - Plants vs. Zombies - [二分+贪心][2018 ACM-ICPC Asia Qingdao Regional Problem E]的更多相关文章

  1. 2018 青岛ICPC区域赛E ZOJ 4062 Plants vs. Zombie(二分答案)

    Plants vs. Zombies Time Limit: 2 Seconds      Memory Limit: 65536 KB BaoBao and DreamGrid are playin ...

  2. ZOJ 4062 Plants vs. Zombies(二分答案)

    题目链接:Plants vs. Zombies 题意:从1到n每个位置一棵植物,植物每浇水一次,增加ai高度.人的初始位置为0,人每次能往左或往右走一步,走到哪个位置就浇水一次.求m步走完后最低高度的 ...

  3. 【非原创】ZOJ - 4062 Plants vs. Zombies【二分】

    题目:戳这里 题意:机器人走过一个花,可以给那个花浇水,给定步数下,问花的最小的最大能量值. 学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 typ ...

  4. ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...

  5. ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...

  6. ZOJ 4063 - Tournament - [递归][2018 ACM-ICPC Asia Qingdao Regional Problem F]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4063 Input Output Sample Input 2 3 ...

  7. ZOJ 4070 - Function and Function - [签到题][2018 ACM-ICPC Asia Qingdao Regional Problem M]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5840 Time Limit: 1 Second Mem ...

  8. 2020 ICPC Asia Taipei-Hsinchu Regional Problem H Optimization for UltraNet (二分,最小生成树,dsu计数)

    题意:给你一张图,要你去边,使其成为一个边数为\(n-1\)的树,同时要求树的最小边权最大,如果最小边权最大的情况有多种,那么要求总边权最小.求生成树后的所有简单路径上的最小边权和. 题解:刚开始想写 ...

  9. 2019 ICPC Asia Taipei-Hsinchu Regional Problem K Length of Bundle Rope (贪心,优先队列)

    题意:有\(n\)堆物品,每次可以将两堆捆成一堆,新堆长度等于两个之和,每次消耗两个堆长度之和的长度,求最小消耗使所有物品捆成一堆. 题解:贪心的话,每次选两个长度最小的来捆,这样的消耗一定是最小的, ...

随机推荐

  1. Couldn't find log associated with operation handle: OperationHandle [opType=EXECUTE_STATEMENT, getHandleIdentifier ()=5687ff62-aa71-4b47-af6c-89f6a3f7a1fe]

    这个异常的出现是因为hive-site-xml中的hive.server2.logging.operation.log.location属性未配置正确: 修改为: <property> & ...

  2. 【WCF】解析WCF服务的搭建

    WCF是.NET提供的一种服务,可以将自己写的程序(完成特定功能,比如从数据库中读取数据操作等)分装成服务以后,发布到服务器上.然后会生成一个网址,客户端在编程的时候,可以引用这个服务,使用这个服务中 ...

  3. redmine在linux上的mysql性能优化方法与问题排查方案

    iredmine的linux服务器mysql性能优化方法与问题排查方案     问题定位:   客户端工具: 1. 浏览器inspect-tool的network timing工具分析   2. 浏览 ...

  4. Spring Boot系列——日志配置

    日志,通常不会在需求阶段作为一个功能单独提出来,也不会在产品方案中看到它的细节.但是,这丝毫不影响它在任何一个系统中的重要的地位. 为了保证服务的高可用,发现问题一定要即使,解决问题一定要迅速,所以生 ...

  5. Atitit 数据库排除某一列 字段 显示

    Atitit  数据库排除某一列 字段  显示 GROUP_CONCAT  行列转换 mysql利用group_concat()合并多行数据到一行_Mysql_脚本之家 sELECT GROUP_CO ...

  6. Atitit orm的实现模式 data-mapper模式和active-record模式有什么区别

    Atitit orm的实现模式  data-mapper模式和active-record模式有什么区别 1.1. 这是来自Node.js路线有关混合两种ORM模式Active Record(活动记录模 ...

  7. [k8s]debug模式启动集群&k8s常见报错集合(on the fly)

    debug模式启动-支持sa 集群内(pod访问api)使用443加密 no1 no2 安装flanneld kubelet/kube-proxy m1 安装etcd/ api/contruller/ ...

  8. oracle学习创建和准备Oracle样例数据库

    此处有一个Oracle创建数据库和表和插入数据的脚本: http://www.forta.com/books/0672336073/

  9. 明天软软onsite

    现在在飞机上,还有1.5小时到达.买了网络包,速度不错.今年上半年第三次飞西雅图,过几天也许还有第四次... 今天群主FB加面系统设计非常顺利,祝他拿到大包裹,也希望拿到以后发大红包,这回我一定不能错 ...

  10. springmvc 拦截通配符 /** /

    /** 拦截所有 包括 *.js *.css *.png 等等 / 只拦截 /login, /logout, /index等等