数学 之 Codeforces 354A - Vasya and Robot
2014-07-13 11:14
435 查看
// [7/13/2014 Sjm] /* 据题意知道: 假设重物用左手拿,则该重物左边的所有重物都是用左手拿 假设重物用右手拿,则该重物右边的所有重物都是用右手拿 从左手出发: 1)左手没拿重物 2)左手拿1或2或...或n个重物 故:枚举 (n+1) 种情况即可 注意(详见代码): 1)对一段区间内的重物重量之和的处理(O(1))。 2)注意,假设左手共拿 m 个重物,右手共拿 n 个重物,只有当 abs(n-m) > 1 时,才会考虑额外费用, 否则通过交替拿左右边的重物,可不计额外费用。 */
#include <iostream> #include <cstdlib> #include <cstdio> using namespace std; const int MAX = 100005; int arr[MAX]; int main() { int n, l, r, Ql, Qr; scanf("%d %d %d %d %d", &n, &l, &r, &Ql, &Qr); for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); if (i != 0) { arr[i] += arr[i - 1]; // 为了方便计算一段区间内的重物重量之和 } } int ans = arr[n - 1] * r + (n - 1)*Qr; // 左手不拿重物的情况 int tep; for (int i = 0; i < n; i++) { // 枚举左手拿重物的 n 种情况 tep = arr[i] * l + (arr[n - 1] - arr[i])*r; int l_num = i + 1; int r_num = n - l_num; int Judge = r_num - l_num; if (abs(Judge) > 1) { if (Judge > 0) { Judge--; tep += (Judge * Qr); } if (Judge < 0){ Judge++; tep += ((-Judge) * Ql); } } ans = (ans < tep) ? ans : tep; } printf("%d\n", ans); return 0; }
相关文章推荐
- 数学 之 Codeforces 354A - Vasya and Robot
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
- CodeForces 354A - Vasya and Robot (简单思维)
- CodeForces 493 E.Vasya and Polynomial(数学)
- codeforces 355C - Vasya and Robot
- Codeforces 355C Vasya and Robot【贪心+前缀和】
- CodeForces 493 E.Vasya and Polynomial(数学)
- Codeforces 355C Vasya and Robot 暴力枚举
- CodeForces - 748C Santa Claus and Robot(思维)
- Codeforces 584D Dima and Lisa 【数学】
- 数学 - Codeforces Round #319 (Div. 1)A. Vasya and Petya's Game
- Codeforces 676C - Vasya and String 详解(二分前缀和+尺取两种写法)
- codeforces 676C C. Vasya and String 尺取法
- codeforces 354 div2 C Vasya and String 前缀和
- CodeForces 553 B.Kyoya and Permutation(组合数学)
- CodeForces 366A Dima and Guards(结构体,数学)
- A. Vasya and Robot----思维题
- CodeForces 715A. Plus and Square Root(数学,脑洞题)
- codeforces 374A Inna and Pink Pony(数学)
- CodeForces 476B Dreamoon and WiFi 数学 概率 DP