CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
来源:互联网 发布:vb single double 编辑:程序博客网 时间:2024/04/27 22:32
题意:
有一列东西..现在有个机器人要取走这些东西..机器人 有左手和右手...每个物品有重量W1,W2,W3...Wn-1,Wn..左手只能从还剩下的物品最左侧取...右手只能从剩下的物品最右侧取....若机器人用左手取走物品Wi..那么所需要的能量为Wi*l...若机器人用右手取走物品Wi..那么所需要的能量为Wi*r...并且若机器人上一步用左手..这一步也用左手..需要额外付出能量Ql...若机器人上一步用右手..这一步也用右手..需要额外付出能量Qr..现在问要取完所有物品..最少要多少能量
题解:
思路很简单..因为每次要么从左侧要么从右侧..那么最后的结果肯定是左边的i个是从左侧取的..右边的n-i个是从右侧取的..那么做了预处理后枚举i就好..然后因为连续相同边取会有损失..所以枚举了中点后..可以算出某一侧(只可能一侧)要必须连续取多少次.那么就可以算出当前情况下的代价了..
很快就写了.. 然后提交Pretest Passed..结果赛后跑完整数据.居然跪了.一看错得情况.是因为初值给小了...哎...没看清题..根本没注意..
Program:
#include<iostream>#include<stdio.h>#include<string.h>#include<queue>#include<stack>#include<algorithm>#include<cmath>#include<set>#include<map>#define ll long long#define oo 1<<30#define pi acos(-1.0)#define MAXN 300005#define esp 1e-30using namespace std; int a[MAXN],suml[MAXN],sumr[MAXN];int main(){ int i,n,l,r,L,R,Ql,Qr,ans,w; scanf("%d%d%d%d%d",&n,&l,&r,&Ql,&Qr); for (i=1;i<=n;i++) scanf("%d",&a[i]); suml[0]=sumr[n+1]=0; for (i=1;i<=n;i++) suml[i]=suml[i-1]+a[i]; for (i=n;i>=1;i--) sumr[i]=sumr[i+1]+a[i]; ans=oo; for (i=0;i<=n;i++) { w=suml[i]*l+sumr[i+1]*r; L=i,R=n-L; if (L>R+1) w+=(L-R-1)*Ql; if (R>L+1) w+=(R-L-1)*Qr; ans=min(ans,w); } printf("%d\n",ans); return 0;}
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
- CodeForces 354A - Vasya and Robot (简单思维)
- codeforces 354A Vasya and Robot [思维]
- A. Vasya and Robot----思维题
- 数学 之 Codeforces 354A - Vasya and Robot
- codeforce 354A Vasya and Robot
- Codeforces Round #206 (Div. 1) A. Vasya and Robot
- codeforces 355C Vasya and Robot
- Codeforces A. Vasya and Socks
- Vasya and Robot
- C. Vasya and Robot
- ASP变量不能赋初值
- Codeforces Round #206 (Div. 2) C - Vasya and Robot
- Codeforces Round #206 (Div. 2) C. Vasya and Robot
- Codeforces Round #206 (Div. 2) C-Vasya and Robot
- Codeforces 355C Vasya and Robot 暴力枚举
- [Codeforces] 355A - Vasya and Digital Root
- codeforces-#460A Vasya and Socks
- ADB server didn't ACK-----eclipse连接不上模拟器
- triangle.vp
- 站起来继续前进
- WPF元素绑定--简单
- 交换友链需要注意的nofollow标签
- CodeForces 354A - Vasya and Robot 简单思维..赋初值一定不能随便了T_T
- Linux下时间同步
- wen7系统下用vc6.0读取摄像头
- triangle.fp
- texturedTriangle.vp
- texturedTriangle.fp
- iOS开发27:打包应用程序
- C语言宏定义中的#,##,#@及\符号的作用
- NDK调用参数有jstring的问题