C. Vasya and Robot
2013-10-23 22:23
375 查看
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has n items lying in a line. The items are consecutively numbered by numbers from
1 to n in such a way that the leftmost item has number
1, the rightmost item has number
n. Each item has a weight, the i-th item weights
wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight
of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra
Ql energy units;
Take the rightmost item with the right hand and spend
wj · r energy units (wj is a weight of the rightmost item,
r is some parameter). If the previous action was the same (right-hand), then the robot spends extra
Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr
(1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers
w1, w2, ..., wn
(1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Sample test(s)
Input
Output
Input
Output
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends
4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends
(2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
思路:1.题目。。英语易理解错,这不能算一个dp问题,最先理解成类似流水线换道的问题了
2.除此之外就是找一个数组中,某个位置左右元素数量差的技巧了
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has n items lying in a line. The items are consecutively numbered by numbers from
1 to n in such a way that the leftmost item has number
1, the rightmost item has number
n. Each item has a weight, the i-th item weights
wi kilograms.
Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:
Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight
of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra
Ql energy units;
Take the rightmost item with the right hand and spend
wj · r energy units (wj is a weight of the rightmost item,
r is some parameter). If the previous action was the same (right-hand), then the robot spends extra
Qr energy units;
Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.
Input
The first line contains five integers n, l, r, Ql, Qr
(1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104).
The second line contains n integers
w1, w2, ..., wn
(1 ≤ wi ≤ 100).
Output
In the single line print a single number — the answer to the problem.
Sample test(s)
Input
3 4 4 19 1 42 3 99
Output
576
Input
4 7 2 3 9 1 2 3 4
Output
34
Note
Consider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends
4·42 + 4·99 + 4·3 = 576 energy units.
The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends
(2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.
思路:1.题目。。英语易理解错,这不能算一个dp问题,最先理解成类似流水线换道的问题了
2.除此之外就是找一个数组中,某个位置左右元素数量差的技巧了
#include <iostream> #define SIZE 100000 int w[SIZE]; int sum[SIZE]; using namespace std; int n, l, r, ql, qr; int main() { int i, val , ans = -1; cin >> n >> l >> r >> ql >> qr; sum[0] = 0; for(i = 1; i <=n; i++){ cin >> w[i]; sum[i] += sum[i - 1] + w[i]; } for( i = 0; i <= n; i++){ val = sum[i]*l + (sum - sum[i])*r; //normal cost do{ if( 2*i - n > 1){ val += (2*i - n - 1)*ql; break; } if( n - 2*i > 1){ val += (n - 2*i - 1)*qr; break; } }while(0); if(-1 == ans|| ans > val) ans = val; } cout << ans << endl; return 0; }
相关文章推荐
- 数学 之 Codeforces 354A - Vasya and Robot
- codeforce C - Vasya and Robot
- Vasya and Robot
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- [CF355C]Vasya and Robot(思维,贪心)
- A. Vasya and Robot----思维题
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
- codeforces 355C - Vasya and Robot
- cf C. Vasya and Robot
- Vasya and Robot
- Codeforces 355C Vasya and Robot【贪心+前缀和】
- CF#354 A. Vasya and Robot(思维题)
- 【CF1073C】Vasya and Robot(二分,构造)
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- CodeForces 354A - Vasya and Robot (简单思维)
- Codeforces 355C Vasya and Robot 暴力枚举
- 数学 之 Codeforces 354A - Vasya and Robot
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Install RL(Robotcs Library) on ubuntu and using