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 ???

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<string>
 6 #include<cstdio>
 7 #include<queue>
 8 #include<vector>
 9 typedef long long ll;
10 #define maxn 100005
11 using namespace std;
12
13 ll a[maxn];
14 ll book[maxn];
15 ll n,m,ans,Min;
16 bool Check(ll mid){
17     ll tmp;
18     if(mid==0) {
19         Min=0;
20         return true;
21     }
22     Min=0x3f3f3f3f3f3f3f3f;
23     for(int i=1;i<=n+1;i++){
24         book[i]=0;
25     }
26     for(int i=1;i<=n;i++){
27         tmp=mid/a[i];
28         if(a[i]*tmp<mid) tmp++;
29         if(i==n&&book[i]>=tmp) break;
30         book[i]++;
31         if(book[i]<tmp){
32             book[i+1]+=tmp-book[i];
33             book[i]=tmp;
34         }
35         Min=min(Min,a[i]*book[i]);
36     }
37     ll sum=0;
38     for(int i=1;i<=n+1;i++){
39         sum+=book[i];
40         if(sum>m) return false;
41     }
42     return true;
43 }
44
45 int main(){
46     int T;
47     while(~scanf("%d",&T)){
48         while(T--){
49             scanf("%lld %lld",&n,&m);
50             for(int i=1;i<=n;i++){
51                 scanf("%lld",&a[i]);
52             }
53             ll L,R,mid;
54             L=0,R=(1LL<<60);
55             while(L<=R){
56                 mid=(L+R)/2;
57                 if(Check(mid)){
58                     L=mid+1;
59                   //  ans=Min;
60                 }
61                 else{
62                     R=mid-1;
63                 }
64             }
65             printf("%lld\n",L-1);
66         }
67     }
68 }

View Code

转载于:https://www.cnblogs.com/Fighting-sh/p/9939747.html

Plants vs. Zombies(二分好题+思维)相关推荐

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

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

  2. ZOJ4062 Plants vs. Zombies 二分

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

  3. 2018 ACM-ICPC 亚洲区域赛青岛站 E - Plants vs. Zombies(二分)

    题意 有n个植物,m次移动1格的机会, 以下n个数a1-an,代表每一次浇水(其实就是访问),该处的植物会增加防御值ai,初始防御值di=0 n个植物分别在坐标轴1,-,n的位置,浇水机的位置初始在0 ...

  4. Plants vs. Zombies(二分)

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

  5. Plants vs. Zombies【二分】

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

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

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

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

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

  8. Plants vs. Zombies

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

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

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

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

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

最新文章

  1. python小项目案例-Python小项目:快速开发出一个简单的学生管理系统
  2. 9月份个人:windows系统的DNS服务器配置
  3. yolo_model to output理解
  4. Android Service 之 AIDL
  5. linux代码调节亮度,linux 屏幕亮度调整命令
  6. Java IO篇:序列化与反序列化
  7. 【CAS】Implementing generic double-word compare and swap for x86/x86-64
  8. aws linux使用ssh登陆_【Linux】 使用ssh连接远程服务器
  9. 查看Ubuntu内核和版本的两条命令以及LTS的含义
  10. Inno Setup 操作XML
  11. HAproxy的安装配置及动静分离
  12. 中国移动苏州研发中心前端笔试(2)
  13. 汽车软件质量体系DIY(1)难题-价值-周期
  14. 【计算机组成原理】重点总结(详版)
  15. matlab空间计量AIC准则,关于AIC准则
  16. SPOJ 28270 BIPCSMR16 - Team Building(水~)
  17. 美国计算机金融排名大学排名,2018usnews美国大学金融专业研究生top30排名
  18. 微信支付要租用服务器吗,切记!使用微信支付一定要打开这些功能!
  19. ESP32-C3入门教程 基础篇(六、TIMG 硬件定时器 与 软件定时器)
  20. Windows搭建SFTP文件服务器

热门文章

  1. 深入了解Oracle数据字典升级脚本catupgrd.sql调用过程
  2. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree
  3. 一个IE动画图标的小例子
  4. 家居有线网络布线方案(转)
  5. hdu P3374 String Problem
  6. 1、爱因斯相对论(狭义相对论)
  7. LNMP 1.2/1.3+升级Nginx、MySQL/MariaDB、PHP教程
  8. Django 【第六篇】ORM跨表操作(聚合查询,分组查询,F和Q查询等)
  9. java比较器Comparator 和 Comparable 的区别
  10. python--递归、二分查找算法