bzoj1045: [HAOI2008] 糖果传递
来源:互联网 发布:做淘宝天猫优惠券 编辑:程序博客网 时间:2024/05/22 15:37
链接
http://www.lydsy.com/JudgeOnline/problem.php?id=1045
题解
因为数组开成了int导致1A连击中止..本次1A连击数:2
设第i个人给第i-1个人的糖果数为
那就是最小化
这样没法做,需要找等量关系消元。设
那么
令
可以得到
那就成了最小化
将
代码
//神奇题目#include <cstdio>#include <algorithm>#include <cmath>#define ll long long#define maxn 1000010using namespace std;ll x[maxn], y[maxn], N, a[maxn], tmp[maxn];ll read(ll x=0){ char c=getchar(); while(c<48 or c>57)c=getchar(); while(c>=48 and c<=57)x=(x<<1)+(x<<3)+c-48, c=getchar(); return x;}int main(){ ll i, ans=0; N=read(); for(i=1;i<=N;i++)a[i]=read(), a[0]+=a[i]; a[0]/=N; for(i=1;i<=N;i++)y[i]=a[0]-a[i]+y[i-1]; for(i=1;i<=N;i++)tmp[i]=-y[i]; sort(tmp,tmp+N); x[1]=tmp[(0+N+1)>>1]; for(i=2;i<=N;i++)x[i]=y[i-1]+x[1]; for(i=1;i<=N;i++)ans+=abs(x[i]); printf("%lld",ans); return 0;}
0 0
- BZOJ1045 HAOI2008糖果传递
- bzoj1045: [HAOI2008] 糖果传递
- [BZOJ1045][HAOI2008]糖果传递
- bzoj1045【haoi2008】糖果传递
- BZOJ1045[HAOI2008] 糖果传递
- bzoj1045: [HAOI2008] 糖果传递
- bzoj1045: [HAOI2008] 糖果传递
- bzoj1045 [HAOI2008] 糖果传递
- 【BZOJ1045】【HAOI2008】糖果传递
- BZOJ1045: [HAOI2008] 糖果传递
- [BZOJ1045][HAOI2008][贪心]糖果传递
- bzoj1045: [HAOI2008] 糖果传递 贪心
- 【bzoj1045】 HAOI2008糖果传递 中位数
- bzoj1045/1465 [HAOI2008]糖果传递
- [BZOJ1045]HAOI2008糖果传递|中位数|数学
- [BZOJ1045][HAOI2008] 糖果传递(数学相关)
- bzoj3293 [Cqoi2011]分金币&&bzoj1045 [HAOI2008]糖果传递
- 【BZOJ1045】[HAOI2008] 糖果传递【绝对值不等式】【中位数】【数形结合】
- asp.net mvc 之旅 —— 第五站 从源码中分析asp.net mvc 中的TempData
- javascript
- linux多进程通讯
- asp.net mvc 之旅 —— 第六站 ActionFilter的应用及源码分析
- mongodb 3.x 之实用新功能窥看[1] ——使用TTLIndex做Cache处理
- bzoj1045: [HAOI2008] 糖果传递
- Linux(Centos)安装tomcat
- 机器学习资料分享
- mongodb 3.x 之实用新功能窥看[2] ——使用$lookup做多表关联处理
- mongodb之使用explain和hint性能分析和优化
- Java基础知识点
- knockoutjs如何动态加载外部的file作为component中的template数据源
- sql添加字段
- c#简单的客车售票系统(《c#程序设计慕课版-甘勇 尚展垒编著》第二章上机指导)