ZOJ - 4062

BaoBao and DreamGrid are playing the game Plants vs. Zombies. In the game, DreamGrid grows plants to defend his garden against BaoBao’s zombies.

(Image from pixiv. ID: 21790160; Artist: socha) There are nnn plants in DreamGrid’s garden arranged in a line. From west to east, the plants are numbered from 1 to nnn and the iii-th plant lies iii meters to the east of DreamGrid’s house. The iii-th plant has a defense value of did_idi​ and a growth speed of aia_iai​. Initially, di=0d_i = 0di​=0 for all 1≤i≤n1 \le i \le n1≤i≤n.DreamGrid uses a robot to water the plants. The robot is in his house initially. In one step of watering, DreamGrid will choose a direction (east or west) and the robot moves exactly 1 meter along the direction. After moving, if the iii-th plant is at the robot’s position, the robot will water the plant and aia_iai​ will be added to did_idi​. Because the water in the robot is limited, at most mmm steps can be done.The defense value of the garden is defined as min⁡{di∣1≤i≤n}\min{d_i | 1 \le i \le n}min{di​∣1≤i≤n}. DreamGrid needs your help to maximize the garden’s defense value and win the game.Please note that:Each time the robot MUST move before watering a plant;It’s OK for the robot to move more than nnn meters to the east away from the house, or move back into the house, or even move to the west of the house.InputThere are multiple test cases. The first line of the input contains an integer TTT, indicating the number of test cases. For each test case:The first line contains two integers nnn and mmm (2≤n≤1052 \le n \le 10^52≤n≤105, 0≤m≤10120 \le m \le 10^{12}0≤m≤1012), indicating the number of plants and the maximum number of steps the robot can take.The second line contains nnn integers a1,a2,…,ana_1, a_2, \dots, a_na1​,a2​,…,an​ (1≤ai≤1051 \le a_i \le 10^51≤ai​≤105), where aia_iai​ indicates the growth speed of the iii-th plant.It’s guaranteed that the sum of nnn in all test cases will not exceed 10610^6106.OutputFor 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 Output6
4
HintIn the explanation below, ‘E’ indicates that the robot moves exactly 1 meter to the east from his current position, and ‘W’ indicates that the robot moves exactly 1 meter to the west from his current position.For the first test case, a candidate direction sequence is {E, E, W, E, E, W, E, E}, so that we have d={6,6,12,6}d = {6,6,12,6}d={6,6,12,6} after the watering.For the second test case, a candidate direction sequence is {E, E, E, E, W, E, W, E, W}, so that we have d={10,10,4}d = {10, 10, 4}d={10,10,4} after the watering.

思路:这道题是求最小值的最大情况,可以考虑二分答案。我们对defense value进行二分。当defense value确定下来后,在确定m步之后能否满足当前的defense value,能满足说明答案要小于等于当前的defense value,否则就大于等于,相应进行二分即可。判断见代码注释。

代码

#include <stdio.h>
#include <stdbool.h>
inline int min(int Left,int Right){return Left<Right?Left:Right;
}int T;long long n, m;
int Grow[200005];
long long Times[200005];//判断m步能是高度全部大于high												

Plants vs. Zombies相关推荐

  1. zoj4062 Plants vs. Zombies 二分+模拟(贪心的思维)

    题目传送门 题目大意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai,现在机器人从第0个格子出发,每次走一步,不能停留,每一步浇一次水,总共可以走 ...

  2. Plants vs. Zombies(二分)

    文章目录 [Plants vs. Zombies](https://zoj.pintia.cn/problem-sets/91827364500/problems/91827370312) 题意 解题 ...

  3. 植物大战僵尸(Plants vs. Zombies)Mac版本

    游戏介绍 可怕的僵尸即将入侵你的家,唯一的防御方式就是你栽种的植物!武装你的植物,切换他们不同的功能,诸如强悍的豌豆射手或樱桃炸弹,更加快速有效的将僵尸阻挡在入侵的道路上.不同的敌人,不同的玩法构成五 ...

  4. Plants vs. Zombies【二分】

    ZOJ - 4062 Plants vs. Zombies BaoBao and DreamGrid are playing the game Plants vs. Zombies. In the g ...

  5. 关于植物大战僵尸| Plants VS Zombies 运行时 Fatal Error

    系统/System:Win 10 游戏版本Game Version:Plants VS Zombies 1.0 英文原版 下载链接见PZ的贴吧,或: 植物大战僵尸链接 下载的资源无需安装就可直接运行. ...

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

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

  7. ZOJ4062 Plants vs. Zombies 二分

    ZOJ4062 Plants vs. Zombies 一机器人给植物浇水,浇水之前必须移动一格,移动后必须浇水,从1~n的位置上有n个植物,每个植物都有自己的生长速度, 每浇一次生长一次,机器人初始位 ...

  8. ZOJ 4062 Plants vs. Zombies(二分)

    ZOJ 4062 Plants vs. Zombies 意义不明的花妈和芳香. There are plants in DreamGrid's garden arranged in a line. F ...

  9. 2018ICPC青岛区域赛 zoj4062 Plants vs. Zombies

    2018ICPC青岛区域赛 zoj4062 Plants vs. Zombies BaoBao and DreamGrid are playing the game Plants vs. Zombie ...

最新文章

  1. SSRS配置2:加密管理
  2. jvm三:jvm参数
  3. 细说反射,Java 和 Android 开发者必须跨越的坎
  4. 使用swoole进行消息推送通知,配合vb.net进行客户端开发一样爽[开发篇]
  5. 今晚直播 | 清华大学​高天宇:对比学习及其在NLP中的应用
  6. Python中的select、epoll详解
  7. 你为什么喜欢VIM?
  8. python 验证数据类型函数
  9. 12.2 新特性:锁信息获取之在线删除索引
  10. 2017-2018-1 20155301 20155307 20155339 《信息安全系统设计基础》 实验一 开发环境的熟悉...
  11. ug怎么画曲线_UG怎么画雨伞?ug曲面造型实例教程
  12. 漏洞复现-——通达OA任意用户登陆漏洞
  13. 笔记本android vga输出,笔记本VGA接口基础知识普及
  14. css中“~”(波浪号)、“,”(逗号)、 “ + ”(加号)和 “ ”(大于号)是什么意思?
  15. C++的O2、O3到底是个什么鬼
  16. hand crafted feature:histogram(直方图)
  17. JC-1、python学习笔记
  18. C语言实现每次找出最大最小值排序
  19. win10系统sqlserver2000数据库问题
  20. 网易云的特色与优势?|网易云

热门文章

  1. (环境搭建+复现)74CMS模版注入+文件包含getshell
  2. centos7 下双网卡如何配置静态IP
  3. Python-Django毕业设计航空订票系统(程序+Lw)
  4. matlab如何解麦克斯韦方程,麦克斯韦方程组-Read.PPT
  5. 蓝桥杯 ADV-287 算法提高 Monday-Saturday质因子
  6. 0503《软件工程》的简单小总结与展望
  7. rpm包是什么?怎么解压?
  8. c语言中冰雹猜想,趣味冰雹猜想
  9. java 二维表格_实现二维表
  10. 王者荣耀全国最低战区推荐查询,王者荣耀战区实时查询秒上省标