博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Plants vs. Zombies(二分好题+思维)
阅读量:5094 次
发布时间:2019-06-13

本文共 3356 字,大约阅读时间需要 11 分钟。

Plants vs. Zombies

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

24 83 2 6 63 910 10 1

Sample Output

64

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
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 typedef long long ll;10 #define maxn 10000511 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
=tmp) break;30 book[i]++;31 if(book[i]
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

你可能感兴趣的文章
Android Token的使用学习
查看>>
小别离
查看>>
★一张图弄明白从零维到十维
查看>>
Makefile 跟着走快点
查看>>
Java开发学习心得(一):SSM环境搭建
查看>>
固定渲染管线与可编程渲染管线的区别
查看>>
MVC框架
查看>>
IIS在默认情况并不支持对PUT和DELETE请求的支持
查看>>
AS400的触发器(转载)
查看>>
1044 拦截导弹
查看>>
Uploadify使用
查看>>
PriorityQueue 优先队列的实现
查看>>
[Vue]导航守卫:全局的、单个路由独享的、组件级的
查看>>
js中keydown和keypress的区别
查看>>
百度富文本编辑器自动缩放上传的图片
查看>>
从PHP5.0到PHP7.1的性能全评测
查看>>
sql语句中的字符串拼接
查看>>
【例9.11】01背包问题
查看>>
初学Python:基础部分
查看>>
词法分析修改版
查看>>