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步,每一步只能往前走或者往后走,每走到一 ...
随机推荐
- 1050 String Subtraction (20 分)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
- 微信公众平台测试帐号的注册与使用(自己的服务器<---->微信后台<---->测式公众号)
打开注册的网址:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login 用手机微信扫描网页左边的二维码,然后在手机上确认即可: 至此 ...
- Install hadoop on windows(non-virtual machine, such cygwin)
DownloadBefore starting make sure you have this two softwares Hadoop 2.7.1 Java – Jdk 1.7+ Extract d ...
- bitmap运算
概述 所谓bitmap就是用一个bit位来标记某个元素对应的value,而key即是这个元素.由于采用bit为单位来存储数据,因此在可以大大的节省存储空间 算法思想 32位机器上,一个整形,比 ...
- HIbernate编程模型
1.Hibernate: ORM框架,简化SQL开发,编程接口丰富,简化JDBC编程 2.有点: Lazy机制配合Fetch的HQL高级查询,提高开发效率 难点:理解Lazy与Fetch JOIN的原 ...
- SOAP,RESTFull以及RPC的认识
a.一般的系统,开发都是针对数据库开发,不存在系统之间的交互,但是随着现实是有好多系统(好多DB,DB不开放),这些系统之间要进行交互,就像人一样要互相帮助.所以 可以通过一下的方式: 1. ...
- php for 循环使用实例介绍
for 循环用于您预先知道脚本需要运行的次数的情况. 语法 for (初始值; 条件; 增量) { 要执行的代码; } 参数: 初始值:主要是初始化一个变量值,用于设置一个计数器(但可以是任何在循环的 ...
- HTML5 学习之地理定位
html5 获取坐标: <!DOCTYPE HTML> <html> <head> <title>test1.html</title> &l ...
- Firefox内存占用过高解决方法
刚开始使用firefox火狐浏览器的时候,你会发现firefox占用内存大,CPU占用率高,打开网页停顿等问题,其实这些是因为firefox没有进行优化,默认设置是标准的设置的原因,解决方法如下: 一 ...
- 6 unit3-文件操作&函数 review
文件处理相关 1.编码问题 (1)请说明python2 与python3中的默认编码是什么? py2默认ASCII码,py3默认的utf8 (2)为什么会出现中文乱码?你能列举出现乱码的情况有哪几种? ...