bzoj 1045: [HAOI2008] 糖果传递【瞎搞】
感觉我的智商可能不够写题解,就直接截了hzwer的blog 地址http://hzwer.com/2656.html

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;
int n,a[N],c[N],p;
long long sum,ans;
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
a[i]=read(),sum+=a[i];
p=sum/n;
for(int i=2;i<=n;i++)
c[i]=c[i-1]+a[i]-p;
sort(c+1,c+n+1);
int mid=c[(n>>1)+1];
for(int i=1;i<=n;i++)
ans+=abs(c[i]-mid);
printf("%lld",ans);
return 0;
}
bzoj 1045: [HAOI2008] 糖果传递【瞎搞】的更多相关文章
- BZOJ 1045: [HAOI2008] 糖果传递 数学
1045: [HAOI2008] 糖果传递 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1045 Description 有n个小朋友坐 ...
- bzoj 1045: [HAOI2008] 糖果传递 贪心
1045: [HAOI2008] 糖果传递 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1812 Solved: 846[Submit][Stat ...
- [BZOJ 1045] [HAOI2008] 糖果传递
题目链接:BZOJ 1045 Attention:数据范围中 n <= 10^5 ,实际数据范围比这要大,将数组开到 10^6 就没有问题了. 我们先来看一下下面的这个问题. 若 n 个人坐成一 ...
- bzoj 1045 [HAOI2008] 糖果传递——设变量推式子
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1045 费用流TLE. #include<iostream> #include&l ...
- BZOJ 1045 [HAOI2008]糖果传递 ★(环形等分:中位数)
题意 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. 思路 假设平均数是x,且a1给an了k个(k<0说明是an给a1了-k个),那么总代价就 ...
- bzoj 1045 [HAOI2008] 糖果传递 —— 贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1045 好像是贪心...但这是一个环... 看博客:http://hzwer.com/2656 ...
- 【BZOJ 1045】 1045: [HAOI2008] 糖果传递
1045: [HAOI2008] 糖果传递 Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. Input 第一行一个正整数n& ...
- 【BZOJ】1045: [HAOI2008]糖果传递(中位数)
http://www.lydsy.com/JudgeOnline/problem.php?id=1045 白书上有讲 没ac的坑点在,数据范围n<=1,000,000 #include < ...
- 1045: [HAOI2008] 糖果传递 - BZOJ
Description 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1.Input 小朋友个数n 下面n行 aiOutput 求使所有人获得均等糖果的 ...
随机推荐
- Vertex&Frag
一.Vertex&Frag 包含Vertex&Fragment 的Shader叫做顶点&像素着色器,在Vertex的功能函数中,我们侧重于几何计算,如纹理坐标,顶点坐标等:在F ...
- 一个简单的模板了解css+div网页布局
直接附上最终效果图: index.html内容: <html> <!--20170730 soulsjie--> <head> <meta http-equi ...
- [luoguP1136] 迎接仪式(DP)
传送门 每个字母只有两种选择,变成另一个或者不变. 所以f[i][j][k]表示前i个字母有j个j变成z,有k个z变成j 只需要比较j==k时的答案就行 #include <cstdio> ...
- codeforces 369B
#include<stdio.h>//题没读懂,没做出来 int main() { int n,k,l,r,s,s1,m,a,i; while(scanf("%d%d% ...
- Flask组件:flask-sqlalchemy & flask-script & flask-migrate
flask-sqlalchemy组件 项目目录结构: flask目录 # 项目名 |--- flaskdir |--- static # 静态文件 |--- templates # 模板 |--- m ...
- EasyUI单击行数据时动态编写editor
$.extend($.fn.treegrid.methods, { addEditor: function (jq, param) { if (param instanceof Array) { $. ...
- HDU - 2059 龟兔赛跑(多阶段决策dp)
http://acm.hdu.edu.cn/showproblem.php?pid=2059 初始把起点和终点也算做充电站,设dp[i]是到第i个充电站的最短时间,那么dp[n+1]即是乌龟到达终点的 ...
- Core java for impatient 笔记 ch8 流
流stream 使用了数据视图,让你可以在比集合更高的概念上指定操作使用流,你只需要将操作的调度留给实现,例如,假设你要计算某个属性的平均值,你只需要指定数据源和属性,然后流类库会优化计算,比如使用多 ...
- Devu and Flowers lucas定理+容斥原理
Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contain ...
- [bzoj2194]快速傅立叶之二_FFT
快速傅立叶之二 bzoj-2194 题目大意:给定两个长度为$n$的序列$a$和$b$.求$c$序列,其中:$c_i=\sum\limits_{j=i}^{n-1} a_j\times b_{j-i} ...