因为在允许的情况下,必然是左右手交替进行,这样不会增加多余的无谓的能量。

然后根据不同的分界点,肯定会产生左手或右手重复使用的情况,这是就要加上Qr/Ql * 次数。

一开始的想法,很直接,枚举每个分界点,计算出总共要用的能量,取最小的那个即是答案:

 #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,l,r,Q_l,Q_r,w[+];
scanf("%d%d%d%d%d",&n,&l,&r,&Q_l,&Q_r);
for(int i=;i<=n;i++) scanf("%d",&w[i]); int ans=,left_enegry_sum,right_enegry_sum;
for(int m=;m<=n;m++) //边界在m右边
{
left_enegry_sum=,right_enegry_sum=;
for(int i=;i<=m;i++) left_enegry_sum+=w[i]*l;
for(int i=n;i>m;i--) right_enegry_sum+=w[i]*r;
if(m < n-m) //右手拿的东西多
right_enegry_sum += ( (n-m) - m - ) * Q_r;
else if(m > n-m) //左手拿的东西多
left_enegry_sum += ( m - (n-m) - ) * Q_l;
ans=min(ans , left_enegry_sum + right_enegry_sum);
//printf("now:\n\tleft_enegry_sum=%d\tright_enegry_sum=%d\tenegry_sum=%d\n",left_enegry_sum,right_enegry_sum,ans);
}
printf("%d\n",ans);
}

但是在数据来那个很大的情况下会超时。

所以考虑到我们的枚举分界点方向是从左到右,那么我们不需要每次枚举分界点都O(n)地去计算左右手拿物品的能量

 #include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,l,r,Q_l,Q_r,w[+];
scanf("%d%d%d%d%d",&n,&l,&r,&Q_l,&Q_r);
for(int i=;i<=n;i++) scanf("%d",&w[i]); w[]=; int ans=,left_energy_sum=,right_energy_sum=;
for(int i=;i<=n;i++) right_energy_sum+=w[i]*r;
for(int m=;m<=n;m++) //边界在m右边
{
left_energy_sum+=w[m]*l; //分界点右移一位,left_enrgy_sum增加新增的那一个物品消耗的能量即可
right_energy_sum-=w[m]*r; //分界点右移一位,right_enrgy_sum减少那一个物品消耗的能量即可
if(m < n-m) //右手拿的东西多
ans=min(ans , left_energy_sum + right_energy_sum + ( (n-m) - m - ) * Q_r);
else if(m > n-m) //左手拿的东西多
ans=min(ans , left_energy_sum + ( m - (n-m) - ) * Q_l + right_energy_sum);
else //两只手拿的一样多
ans=min(ans , left_energy_sum + right_energy_sum);
//printf("now:\n\tleft_energy_sum=%d\tright_energy_sum=%d\tenergy_sum=%d\n",left_energy_sum,right_energy_sum,ans);
}
printf("%d\n",ans);
}

codeforces 355C - Vasya and Robot的更多相关文章

  1. Codeforces 1073C Vasya and Robot 【二分】

    <题目链接> 题目大意: 一个机器人从(0,0)出发,输入一段指令字符串,和机器人需要在指定步数后到达的终点,问如果机器人需要在指定步数内到达终点,那么需要对原指令字符串做出怎样的改变,假 ...

  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. Codeforces 1073C:Vasya and Robot(二分)

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

  4. Codeforces Round #115 A. Robot Bicorn Attack 暴力

    A. Robot Bicorn Attack Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/17 ...

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

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

  6. CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26

    /* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...

  7. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot

    题意:给出一段操作序列 和目的地 问修改(只可以更改 不可以删除或添加)该序列使得最后到达终点时  所进行的修改代价最小是多少 其中代价的定义是  终点序号-起点序号-1 思路:因为代价是终点序号减去 ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)

    题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1;   这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...

  9. Educational Codeforces Round 53 (Rated for Div. 2) C Vasya and Robot 二分

    题目:题目链接 思路:对于x方向距离与y方向距离之和大于n的情况是肯定不能到达的,另外,如果n比abs(x) + abs(y)大,那么我们总可以用UD或者LR来抵消多余的大小,所以只要abs(x) + ...

随机推荐

  1. 教你解锁被锁住的苹果mac电脑的文件跟文件夹,同时也可删除被锁的文件跟文件夹(转)

    在Mac OSX 下无法删除的文件可大概分为下列三种情形 1.档案(夹)被锁定 2.文件正在使用中 3.没有权限的档案(夹) 一.「 为什么档案会被锁定 」 1.个人自行替档案加上 2.在拷贝或是整理 ...

  2. Android输出日志到电脑磁盘

    使用Eclipse查看Log有时候挺恶心的,有些Log ADB会自动的清除,所有有时候导致抓不到有效的Log,把Log保存到文件,然后通过文本查看器查看,感觉好Happy,下面就是脚本文件: adb ...

  3. SpringBoot------新建一个项目

    1.新建一个Maven Project 2.选择项目路劲 3.选择Web App 4.添加项目名称 5.右击“Properties”->“Java Build Path”->“Source ...

  4. centos7 python3.5中引入sqlite3

    在centos系统中创建Django app,报错如下: django.core.exceptions.ImproperlyConfigured: Error loading either pysql ...

  5. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing ___Error Installing APK

    一 : 根据以下路径,找到Instant Run中的选项         File —— Settings——Build,Execution,Deployment——Instant Run       ...

  6. MQTT-C-PUB

    /* ============================================================================ Name        : mqtest ...

  7. (原创)Android Binder设计与实现 - 实现篇(1)

    本文属于原创作品,转载请注明出处并放于明显位置,原文地址:http://www.cnblogs.com/albert1017/p/3849585.html 前言 在学习Android的Binder机制 ...

  8. 【cs229-Lecture3】Logistic回归

    参考: http://www.itongji.cn/article/12112cH013.html http://blog.csdn.net/zouxy09/article/details/20319 ...

  9. 【基础】httpclient注意事项

    一.HttpClient有默认的执行器RetryExec,其默认的重试策略是DefaultHttpRequestRetryHandler. RetryExec在执行http请求的时候使用的是底层的基础 ...

  10. html2canvas - 微信中长按存图 - 将h5活动结果保存到本地

    现在有很多在微信里流行的h5活动页.这些小h5大部分都是简单的交互然后得出一个abcd早就拟定好的结果,根据你的选项分几种情况,最终得到其中一个作为你测试的答案.比如这个就是最后那张结果图: 当时自己 ...