Plants vs. Zombies(二分好题+思维)
Plants vs. Zombies
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5819
BaoBao and DreamGrid are playing the game Plants vs. Zombies. In the game, DreamGrid grows plants to defend his garden against BaoBao's zombies.
Plants vs. Zombies(?)
(Image from pixiv. ID: 21790160; Artist: socha)
There are plants in DreamGrid's garden arranged in a line. From west to east, the plants are numbered from 1 to and the -th plant lies meters to the east of DreamGrid's house. The -th plant has a defense value of and a growth speed of . Initially, for all .
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 -th plant is at the robot's position, the robot will water the plant and will be added to . Because the water in the robot is limited, at most steps can be done.
The defense value of the garden is defined as . 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 meters to the east away from the house, or move back into the house, or even move to the west of the house.
Input
There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:
The first line contains two integers and (, ), indicating the number of plants and the maximum number of steps the robot can take.
The second line contains integers (), where indicates the growth speed of the -th plant.
It's guaranteed that the sum of in all test cases will not exceed .
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
Hint
In 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 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 after the watering.
用ans输出好像会炸long long ???
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdio>
#include<queue>
#include<vector>
typedef long long ll;
#define maxn 100005
using namespace std; ll a[maxn];
ll book[maxn];
ll n,m,ans,Min;
bool Check(ll mid){
ll tmp;
if(mid==) {
Min=;
return true;
}
Min=0x3f3f3f3f3f3f3f3f;
for(int i=;i<=n+;i++){
book[i]=;
}
for(int i=;i<=n;i++){
tmp=mid/a[i];
if(a[i]*tmp<mid) tmp++;
if(i==n&&book[i]>=tmp) break;
book[i]++;
if(book[i]<tmp){
book[i+]+=tmp-book[i];
book[i]=tmp;
}
Min=min(Min,a[i]*book[i]);
}
ll sum=;
for(int i=;i<=n+;i++){
sum+=book[i];
if(sum>m) return false;
}
return true;
} int main(){
int T;
while(~scanf("%d",&T)){
while(T--){
scanf("%lld %lld",&n,&m);
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
}
ll L,R,mid;
L=,R=(1LL<<);
while(L<=R){
mid=(L+R)/;
if(Check(mid)){
L=mid+;
// ans=Min;
}
else{
R=mid-;
}
}
printf("%lld\n",L-);
}
}
}
Plants vs. Zombies(二分好题+思维)的更多相关文章
- zoj4062 Plants vs. Zombies 二分+模拟(贪心的思维)
题目传送门 题目大意:有n个植物排成一排,标号为1-n,每株植物有自己的生长速度ai,每对植物浇一次水,该株植物就长高ai,现在机器人从第0个格子出发,每次走一步,不能停留,每一步浇一次水,总共可以走 ...
- ZOJ 4062 - Plants vs. Zombies - [二分+贪心][2018 ACM-ICPC Asia Qingdao Regional Problem E]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4062 题意: 现在在一条 $x$ 轴上玩植物大战僵尸,有 $n$ ...
- 2018ICPC青岛 E - Plants vs. Zombies (二分+模拟)
ZOJ - 4062 题意:有n个植物排成一排,按顺序植物的编号是1-n,每个植物都有一个生长速率,有一个机器人,机器人可以走m步,每走一步,这个机器人就会浇一次水,浇一次水那个植物就会长 自身的生长 ...
- ZOJ 4062 Plants vs. Zombies(二分答案)
题目链接:Plants vs. Zombies 题意:从1到n每个位置一棵植物,植物每浇水一次,增加ai高度.人的初始位置为0,人每次能往左或往右走一步,走到哪个位置就浇水一次.求m步走完后最低高度的 ...
- 2018 青岛ICPC区域赛E ZOJ 4062 Plants vs. Zombie(二分答案)
Plants vs. Zombies Time Limit: 2 Seconds Memory Limit: 65536 KB BaoBao and DreamGrid are playin ...
- uva 12452 Plants vs. Zombies HD SP (树DP)
Problem I: Plants vs. Zombies HD Super Pro Plants versus Zombies HD Super Pro is a game played not a ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- ZOJ4062 Plants vs. Zombies(二分+贪心)
题目链接:传送门 题目大意: 有n棵植物依次放在1-n,机器人从0出发浇水,每棵植物被浇水时di += ai,求浇m次水后min{di|1 ≤ i ≤ n}的最大值.(浇水时必须往左或往右走一步,落脚 ...
- 2018ACM/ICPC 青岛现场赛 E题 Plants vs. Zombies
题意: 你的房子在0点,1,2,3,...,n(n<=1e5)点每个点都有一颗高度为0的花,浇一次水花会长a[i]. 你有一个机器人刚开始在你家,最多走m步,每一步只能往前走或者往后走,每走到一 ...
随机推荐
- zufe oj 引水工程( 巧妙地把在i建水设为e[0][i])
引水工程 时间限制: 3 Sec 内存限制: 128 MB提交: 11 解决: 6[提交][状态][讨论版] 题目描述 南水北调工程是优化水资源配置.促进区域协调发展的基础性工程,是新中国成立以来 ...
- 1033 To Fill or Not to Fill (25 分)
1033 To Fill or Not to Fill (25 分) With highways available, driving a car from Hangzhou to any other ...
- Ubuntu16.04或18.04上安装QQ微信迅雷
0. 写在前面 没办法,公司的电脑是Windows的,windows下面开发实在太恶心人,并且开发中需要编译golang和C++的程序,于是开始了Linux的折腾之路. 如果你只是想用Linux环境开 ...
- hive的查询注意事项以及优化总结 .
Hive是将符合SQL语法的字符串解析生成可以在Hadoop上执行的MapReduce的工具.使用Hive尽量按照分布式计算的一些特点来设计sql,和传统关系型数据库有区别, 所以需要去掉原有关系型数 ...
- laravel 5.3 ——路由(资源,别名)
laravel的路由定义中,其中route:resoure(),可以直接定义类似restful风格的URL 例如:Route::resource('system/role','System\RoleC ...
- Python入门一:简单得不能再简单了##
从python的语法上看,简单得不能再简单了. 想学它,请移步廖雪峰python2.7教程以及python3.这实在是最好的入门教程.参考资料太多: 外国的教程 Python 入门指南 Python ...
- 在 mvc 4 中使用 unity 进行依赖注入
在 mvc 4 中使用 unity 进行依赖注入 关于依赖注入的概念,这里就不再叙述了,我们用 mvc 4 结合 unity,使用构造函数来进行依 赖注入.具体步骤如下: 1. 首先建立 一个 mvc ...
- IPv4报文分片
1:为什么需要分片 每个数据链路层协议都有自己的帧格式,在这个格式中有一个字段是"数据字段最大长度"(MTU,最大传输单元),当数据报被封装成帧时,数据报的总长度必须小于这个最大长 ...
- UVA-575-水题-模拟
题意: 按照这个公式模拟 10120skew = 1×(25 −1)+0×(24 −1)+1×(23 −1)+2×(22 −1)+0×(21 −1) = 31+0+7+6+0 = 44. #inclu ...
- 使用amaze ui模板全过程
amaze ui基于gulp构建,所以现在安装gulp需要的环境,gulp使用npm安装,npm基于node.js 所以一切从node.js开始 1 下载对应的node.js 打开 https://n ...