BZOJ 3897: Power
3897: Power
Time Limit: 30 Sec Memory Limit: 512 MB
Submit: 218 Solved: 83
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
5 2 2
2 1
Sample Output
HINT
Source
分析:
考虑我们一定是让大的权值尽量被提供较多的体力,并且要求不能溢出,那么考虑分治的思想,定义$f(l,r,be,en)$为从第l天到第r天,初始体力为be结束时体力为en的最优解,我们选择这个区间中权值最大的那个点x,如果这一天前面发那些天都休养生息还不能满足使得第x天的初始体力为E,那么前面几天就歇着吧,否则就是溢出了,溢出是浪费,所以就递归到前面那几天去贡献,后面几天也是一样的...
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std; const int maxn=500000+5; int n,E,R,cas,v[maxn],st[maxn][25]; inline bool cmp(int x,int y){
return v[x]<v[y];
} inline void init(void){
for(int i=1;i<=n;i++)
st[i][0]=i;
for(int j=1;j<=20;j++)
for(int i=1;i+(1<<j-1)<=n;i++)
st[i][j]=max(st[i][j-1],st[i+(1<<(j-1))][j-1],cmp);
} inline int query(int x,int y){
if(x>y)
swap(x,y);
int len=y-x+1,k;
for(k=20;k>=0;k--)
if(((len>>k)&1)||k==0)
break;
return max(st[x][k],st[y-(1<<k)+1][k],cmp);
} inline long long solve(int l,int r,int be,int en){
if(l>r)
return 0;
int id=query(l,r);
long long ans=0,tmp=1LL*(id-l)*R;
if(1LL*be+1LL*tmp>E)
ans=solve(l,id-1,be,E),be=E;
else
be+=tmp;
tmp=1LL*(r-id+1)*R;
if(tmp<en)
en-=tmp;
else
ans+=solve(id+1,r,R,en),en=0;
ans+=1LL*(be-en)*v[id];
return ans;
} signed main(void){
scanf("%d",&cas);
while(cas--){
scanf("%d%d%d",&E,&R,&n);
for(int i=1;i<=n;i++)
scanf("%d",&v[i]);
init();printf("%lld\n",solve(1,n,E,0));
}
return 0;
}
By NeighThorn
BZOJ 3897: Power的更多相关文章
- 3897: Power
题解: 首先很贪心的选择 有最大的我们一定会用最大的 然后可以将序列分割.. 就变成了一道模拟题了.. 每个状态记录(h,t,h-have,t-need) 注意一下细节就可以了 代码: #includ ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- BZOJ 3969 low power
Description 有\(n\)个机器,每个机器有\(2\)个芯片,每个芯片可以放\(k\)个电池.每个芯片能量是\(k\)个电池的能量的最小值.两个芯片的能量之差越小,这个机器就工作的越好.现在 ...
- BZOJ 1622: [Usaco2008 Open]Word Power 名字的能量
题目 1622: [Usaco2008 Open]Word Power 名字的能量 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 349 Solved ...
- bzoj 3969: [WF2013]Low Power 二分
3969: [WF2013]Low Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnli ...
- BZOJ 3969 Low Power 解题报告
我们首先将所有电池排序,那么我们可以找到一组最优方案,使得一台机器的能量之差是相邻两电池的能量之差. 然后我们就二分这个答案,从前往后贪心地选这个数对,然后看是否所有的数对都是满足条件的. 假设这个数 ...
- 【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 这题我搜的题解是dp,我也觉得是dp,但是好像比模拟慢啊!!!! 1400ms不科学! 设f[ ...
- BZOJ——1622: [Usaco2008 Open]Word Power 名字的能量
http://www.lydsy.com/JudgeOnline/problem.php?id=1622 Description 约翰想要计算他那N(1≤N≤1000)只奶牛的名字的能量.每只 ...
- bzoj 1622: [Usaco2008 Open]Word Power 名字的能量【模拟】
模拟即可,注意包含可以是不连续的 方便起见读入的时候全转成小写 #include<iostream> #include<cstdio> using namespace std; ...
随机推荐
- HTML <input> 标签如何屏蔽浏览器的自动填写?
autocomplete = "off",实测无效. <input type="text" autocomplete = "off"/ ...
- 51nod——1402最大值、2479小b分糖果 (套路)
1402最大值:正向从1到n,如果没有限制,就依次递增1,如果有限制,就取那个限制和递增到这的最小值.这样保证1和每个限制点后面都是符合题意的递增,但是限制点前面这个位置可能会有落差(之前递增多了). ...
- Apache 配置默认编码
找到apache配置文件 httpd.conf ,找到以下内容 # # Specify a default charset for all content served; this enables # ...
- nodejs实现前后端交互
本人nodejs入门级选手,站在巨人(文殊)的肩膀上学习了一些相关知识,有幸在项目中使用nodejs实现了前后端交互,因此,将整个交互过程记录下来,方便以后学习. 本文从宏观讲述nodejs实现前后端 ...
- 23.VUE学习之-列表的排序sort
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- python内置函数-排列组合函数
product 笛卡尔积 (有放回抽样排列) permutations 排列 (不放回抽样排列) combinations 组合,没有重复 (不放回抽样组合) combinations_with_re ...
- java流、文件以及IO
读写文件 一个流被定义为一个数据序列.输入流用于从源读取数据,输出流用于向目标写数据. 输入流和输出流的类层次图. FileInputStream FileInputStream用于从文件中读取数据, ...
- easyui-combogrid必填为空时无法通过表单验证的问题
在使用easyui-combogrid时,由于html解析出的格式是如下三层: <td> <input id="txcombo" class="easy ...
- 【Remove Nth Node From End of List】cpp
题目: Given a linked list, remove the nth node from the end of list and return its head. For example, ...
- leetcode 【 Search Insert Position 】python 实现
题目: Given a sorted array and a target value, return the index if the target is found. If not, return ...