vasya (CF_#206_A)
来源:互联网 发布:人工智能算法 编辑:程序博客网 时间:2024/04/19 19:12
题意:给定一个数字串,在串的最左边和最右边来回地取数,
n,l,r,Ql,Qr分别代表数据长度,取左边时乘以的权值,
取右边时乘以的权值,连续两次取左边加上的额外的值
连续取右边时加上的额外的值。
求:使取出的总值最小是多少。
做法:直接假设前i个数是用左边法则取的,其余为右边法则取的。
一个一个地枚举就可以了。
感想:当时晚上做时一下没有想上来就杯具了。
#include<iostream>using namespace std;#define N 100001int n;int go[N];long long sum[N];long long ans;int main(){int i,j,k;intl,r,Ql,Qr;cin>>n>>l>>r>>Ql>>Qr;for (i=1;i<=n;i++)cin>>go[i];sum[0]=0;for (i=1;i<=n;i++)sum[i]=sum[i-1]+go[i];long long cur,temp1,temp2;ans=(n-1)*Qr+sum[n]*r;for (i=1;i<=n;i++){cur=(sum[n]-sum[i])*r+sum[i]*l;j=n-i;if (i-j > 1)cur+=(i-j-1)*Ql;if (j-i > 1)cur+=(j-i-1)*Qr;ans=min(ans,cur);}cout<<ans<<endl;return 0;}
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.
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).
In the single line print a single number — the answer to the problem.
3 4 4 19 142 3 99
576
4 7 2 3 91 2 3 4
34
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.
http://codeforces.com/contest/354/problem/A
- vasya (CF_#206_A)
- CF_#268_DIV2_A_B_D
- CF_#277.5_DIV2_A_B_C
- CF_#302_DIV2_C
- CF_#324(Div.2)
- 二分_A
- cf_#230(Div.2)_pa
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Codeforces Round #206 (Div. 2) B. Vasya and Public Transport
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- Codeforces Round #206 (Div. 2) E. Vasya and Beautiful Arrays
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Codeforces Round #206 (Div. 2) E-Vasya and Beautiful Arrays
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- Codeforces #206(Div.1) C. Vasya and Beautiful Arrays
- 1382_A Simple Task
- @synthesize a=_a
- Android listview中,不同的Item显示不同的layout ---- BaseAdapter
- 软件人员推荐书目(一) 大师篇
- extern用法详解(转)
- Unity3d C#操作数据库异常
- YARN/MRv2 MRAppMaster深入剖析—作业生命周期
- vasya (CF_#206_A)
- MyEclipse开发中常用快捷键
- 2013年10月微软MVP当选名单揭晓!
- 开始了程序员的生活、、、、、
- MonetDB——技巧文章(Client Interfaces客户端接口)
- Android 中ImageView处理图片的工具类
- Activation error occured while trying to get instance of type IcacheManager,key
- 聊天室哈
- YARN/MRv2 MRAppMaster深入剖析—ContainerAllocator分析