[CF355C]Vasya and Robot(思维,贪心)
题目链接:http://codeforces.com/contest/355/problem/C
题意:1~n n个物品各重wi,现在有一个人可以从左边拿和从右边拿, 左边拿一个物品的花费是l*wi,从右边拿是r*wi。然后如果有一次从左边拿的上一次操作也是从左边拿的,就要额外花费ql,同理右边,问最小花费。
眼瞎胡乱跑了一发dp结果T了…
仔细观察就会发现,题意说的是…左手一定从最左边拿,右手一定从最右边拿……
那么一定有一个点,这个点的左手边全是左手拿的,右手边都是右手拿的。
那么枚举这个点,然后再判断这个点左手拿比较好还是右手拿比较好。由于代价都一样,所以可以先计算出两边的分别代价,然后算算某一侧比另一侧多了多少个,也就是需要额外q的花费的个数,贪心地认为这区间是交叉着取的,那么就最后算算多少个q花费就行了。
#include <bits/stdc++.h>
using namespace std; typedef long long LL;
const LL maxn = ;
const LL inf = 0x7f7f7f7f;
int n, l, r, ql, qr;
int w[maxn];
LL ls[maxn], rs[maxn];
LL ret; int main() {
// freopen("in", "r", stdin);
while(~scanf("%d%d%d%d%d",&n,&l,&r,&ql,&qr)) {
memset(ls, , sizeof(ls));
memset(rs, , sizeof(rs));
for(int i = ; i <= n; i++) scanf("%d", &w[i]);
for(int i = ; i <= n; i++) ls[i] = ls[i-] + w[i] * l;
for(int i = n; i >= ; i--) rs[i] = rs[i+] + w[i] * r;
ret = inf;
for(LL i = ; i <= n; i++) {
LL s = ls[i-] + rs[i+];
LL ln = i - , rn = n - i;
if(ln > rn) ret = min(ret, s+(ln-rn-)*ql+min(w[i]*l+ql,w[i]*r));
else if(ln < rn) ret = min(ret, s+(rn-ln-)*qr+min(w[i]*l,w[i]*r+qr));
else ret = min(ret, s+min(w[i]*l,w[i]*r));
}
printf("%I64d\n", ret);
}
return ;
}
[CF355C]Vasya and Robot(思维,贪心)的更多相关文章
- CF 1073C Vasya and Robot(二分答案)
C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...
- 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心
2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Proble ...
- E. The Contest ( 简单DP || 思维 + 贪心)
传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...
- Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】
B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...
- Codeforces 1073C:Vasya and Robot(二分)
C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...
- Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找
The link to problem:Problem - D - Codeforces D. Range and Partition time limit per test: 2 second ...
- C. Vasya and Robot二分
1.题目描述 Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell ...
- 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...
随机推荐
- 雅虎工程师提供的CSS初始化代码
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,b ...
- FastJson之有道翻译
在AndroidMainifast.xml中加入相应的访问权限 <uses-permission android:name="android.permission.INTERNET&q ...
- myeclipse启动报错 no java virtual machine。。。
如果环境变量里已经配置了JAVA_HOME,但是在启动的时候还会提示下面的信息: A Java Runtime Environment (JRE) or Java Development Kit ...
- MySQL之对数据库库表的字符集的更改
数据字符集修改步骤: 对于已有的数据库想修改字符集不能直接通过 "alter database character set *"或 "alter table tablen ...
- poj-3259-wormholes-spfa-判负环
题意:N个顶点, M条双向边, W条权值为负的单向边.求是否存在负环. 思路:首先你要懂bellman-ford或spfa..这是基础的spfa判断是否存在负环的题,存在负环的节点会重复入队(因为最短 ...
- jdbc连接集合
JDBC里统一的使用方法: Class.for(jdbcDriverName); Connection conn=DriverManager.getConnection(url,u ...
- js 表单操作
order.aspx 订单页- order-detail.aspx订单确认页- 操作:order.aspx提交订单@1,跳转到order-detail.aspx页面,确认页面操作:返回上一步@2- ...
- ACM Computer Factory
ACM Computer Factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6104 Accepted: 2113 ...
- Unity-Animator深入系列---Foot IK
回到 Animator深入系列总目录 最近在做一个demo,遇到了角色跑动不自然的问题(注意双腿): 后来得知勾选FootIK之后Unity会智能修复这类问题: 好像这个功能还能做到斜面地形匹配,不过 ...
- js的解析--预处理(三)
js的解析与执行过程 分全局 {预处理阶段和执行阶段} 函数{预处理函数和执行阶段} 1/创建词法环境(环境上下文) LexicalEnvironment === window { } ...