bzoj3293/1045 [Cqoi2011]分金币/[HAOI2008] 糖果传递 贪心
来源:互联网 发布:战斗妖精雪风小说淘宝 编辑:程序博客网 时间:2024/05/17 23:57
圆桌上坐着n个人,每人有一定数量的金币,金币总数能被n整除。每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数目相等。你的任务是求出被转手的金币数量的最小值。n<=1e6.
这个是刘汝佳蓝书P4的原题,还蛮巧妙的。
证明这里也有
http://blog.csdn.net/ycdfhhc/article/details/45437677
#include<bits/stdc++.h>#define LL long long#define clr(x,i) memset(x,i,sizeof(x))using namespace std;const int N=1000005;LL n,a[N],c[N],tot;int main(){scanf("%lld",&n);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);tot+=a[i];}tot/=n;for(int i=2;i<=n;i++) c[i]=c[i-1]+a[i-1]-tot;sort(c+1,c+n+1);LL m=c[(n+1)/2],ans=0;for(int i=1;i<=n;i++) ans+=abs(c[i]-m);printf("%lld",ans);return 0;}
阅读全文
0 0
- bzoj3293/1045 [Cqoi2011]分金币/[HAOI2008] 糖果传递 贪心
- bzoj3293 [Cqoi2011]分金币&&bzoj1045 [HAOI2008]糖果传递
- BZOJ1045(HAOI2008)[糖果传递]&&BZOJ3293(Cqoi2011)[分金币]--中位数
- 【BZOJ】1045 [HAOI2008] 糖果传递 && 3293 [Cqoi2011]分金币 贪心
- 1045: [HAOI2008]糖果传递/3293: [Cqoi2011]分金币
- BZOJ 3293/1465/1045([Cqoi2011]分金币/糖果传递/[HAOI2008] 糖果传递-列方程)
- BZOJ3293: [Cqoi2011]分金币
- bzoj3293 [Cqoi2011]分金币
- [HAOI2008][CQOI2011]糖果传递
- 【BZOJ3293】[Cqoi2011]分金币【绝对值不等式】【中位数】【数形结合】
- bzoj3293 分金币
- [BZOJ1045][HAOI2008][贪心]糖果传递
- bzoj1045: [HAOI2008] 糖果传递 贪心
- bzoj [HAOI2008] 糖果传递 贪心
- 1045: [HAOI2008] 糖果传递
- 1045: [HAOI2008] 糖果传递
- 3293: [Cqoi2011]分金币
- BZOJ 1045: [HAOI2008] 糖果传递
- 【学术】你在读博士期间明白的最深刻的道理是什么?
- G
- 栈的顺序存储实现c++
- Mac下快速搭建PHP开发环境
- 戒骄戒躁戒自傲
- bzoj3293/1045 [Cqoi2011]分金币/[HAOI2008] 糖果传递 贪心
- 记录如何解决通过vpn链接公司内网,但是上不了外网的问题
- Adobe CC2018最新系列所有软件全家桶 破解版 赢政天下@vposy
- PAT刷题:1037. Magic Coupon (25)
- 树莓派3b 远程桌面使用opencv窗口不能显示(Window system doesn't support OpenGL)
- HDU 5437by cyl优先队列
- Coursera Deep Learning 第四课 卷积神经网络 第四周 编程作业 Face Recognition for the Happy House-v3
- JSP页面中的隐含对象
- PHP 分页(limit)