题目链接: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(思维,贪心)的更多相关文章

  1. CF 1073C Vasya and Robot(二分答案)

    C. Vasya and Robot time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. 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 ...

  3. 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 ...

  4. E. The Contest ( 简单DP || 思维 + 贪心)

    传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...

  5. Sorted Adjacent Differences(CodeForces - 1339B)【思维+贪心】

    B - Sorted Adjacent Differences(CodeForces - 1339B) 题目链接 算法 思维+贪心 时间复杂度O(nlogn) 1.这道题的题意主要就是让你对一个数组进 ...

  6. Codeforces 1073C:Vasya and Robot(二分)

    C. Vasya and Robot time limit per test: 1 secondmemory limit per test: 256 megabytesinput: standard ...

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

  8. C. Vasya and Robot二分

    1.题目描述 Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell ...

  9. 【CF1256】Codeforces Round #598 (Div. 3) 【思维+贪心+DP】

    https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价 ...

随机推荐

  1. Swift数据类型简介

    用 Swift 编写 iOS 和 OS X 应用将是一场美妙的体验,Swift 之后也会不断开发新特性和兼容性. Swift 提供了与C.Objective-C的相似的基础数据类型,包含整数Int,浮 ...

  2. XMl的解析简单的方法

    首先需要jia包 xstream-1.4.7.jar Vo类 package com.zld.day06_03zk3demo.bean; import java.io.Serializable; im ...

  3. 【python cookbook】【字符串与文本】7.定义实现最短匹配的正则表达式

    问题:使用正则表达式对文本模式匹配,将识别出来的最长的可能匹配修改为找出最短的可能匹配 解决方法:在匹配模式中的*操作符后加上?修饰符 import re # Sample text text = ' ...

  4. 给文件加ip访问限制

    获取IP: function getIP(){ return isset($_SERVER['HTTP_X_FORWARDED_FOR'])? $_SERVER['HTTP_X_FORWARDED_F ...

  5. Spring JDBC保存枚举对象含关键字报错原因之一

    报错信息: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized S ...

  6. 关于Win7 64位 mysql 5.7下载安装问题

    1.从官网下载mysql: 网址:http://dev.mysql.com/downloads/mysql/ 这是我们要找的,win7 64位 点击下载: 出现如图所示,我们不必要登录注册,点击红线内 ...

  7. C#:反射

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  8. 圆形imageview

    把java代码放到src中,把attrs文件放入valuse中,重新导包,即可照着普通的imageview一样使用. 注意:设置时使用 src 不要使用background否则图片还是方的. circ ...

  9. 使用ResourceBundle访问资源文件(properties)帮助类

    import java.util.ResourceBundle; /** * 读取properties文件的帮助类 * @author */ public class PropertiesUtil { ...

  10. [Unity3D]MonoBehaviour函数介绍

    原文地址: http://www.cocos2dev.com/?p=486 Unity中的脚本都是继承自MonoBehaviour. 一.基础函数: 创建脚本就默认的update.start方法:(这 ...