题意:

”平均数“的意思是:最大数和最小数之间的差值为0或1;

先求“平均”数组,再相减。

 #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<memory.h>
#define clc(a,b) memset(a,b,sizeof(a))
#define ll long long int
using namespace std; int n;
int a[]; int main()
{
while(~scanf("%d",&n))
{
clc(a,);
ll sum=;
ll ans=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sort(a,a+n);
if(sum%n==)
{
int ave=sum/n;
for(int i=;i<n;i++)
ans+=fabs(ave-a[i]);
ans=ans/;
}
else
{
ll res=sum%n;
ll ave=(sum-res)/n;
//int vv=ave;
int b[];
//memset(b,ave,sizeof(b));
for(int i=;i<n;i++)
b[i]=ave;
// cout<<ave<<endl;
// cout<<b[1]<<endl;
for(int i=n-;i>n--res;i--)
{
b[i]+=;
}
// cout<<b[1]<<endl;
// for(int i=0;i<n;i++)
// {
// cout<<b[i]<<endl;
// }
for(int i=;i<n;i++)
{
ans+=fabs(b[i]-a[i]);
}
ans/=;
}
cout<<ans<<endl;
}
return ;
}

609C Load Balancing的更多相关文章

  1. CodeForces 609C Load Balancing

    先算出目标状态,然后拿当前状态与目标状态对比,即可算出答案 #include<cstdio> #include<cmath> #include<cstring> # ...

  2. 【架构】How To Use HAProxy to Set Up MySQL Load Balancing

    How To Use HAProxy to Set Up MySQL Load Balancing Dec  2, 2013 MySQL, Scaling, Server Optimization U ...

  3. CF# Educational Codeforces Round 3 C. Load Balancing

    C. Load Balancing time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  4. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  5. UVA 12904 Load Balancing 暴力

    Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...

  6. Load Balancing 折半枚举大法好啊

    Load Balancing 给出每个学生的学分.   将学生按学分分成四组,使得sigma (sumi-n/4)最小.         算法:   折半枚举 #include <iostrea ...

  7. [zz] pgpool-II load balancing from FAQ

    It seems my pgpool-II does not do load balancing. Why? First of all, pgpool-II' load balancing is &q ...

  8. How Network Load Balancing Technology Works--reference

    http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balan ...

  9. Network Load Balancing Technical Overview--reference

    http://technet.microsoft.com/en-us/library/bb742455.aspx Abstract Network Load Balancing, a clusteri ...

随机推荐

  1. js实现网页图片延时加载的原理和代码 提高网站打开速度

    有时我们看到一些大型网站,页面如果有很多图片的时候,当你滚动到相应的行时,当前行的图片才即时加载的,这样子的话页面在打开只加可视区域的图片,而其它隐藏的图片则不加载,一定程序上加快了页面加载的速度,对 ...

  2. js常识

    btnDelAll.Attributes.Add("onclick", "<script lunguage='javascript'>return windo ...

  3. Eclipse 调整代码颜色的地方

    Editors - Text Editors General-Apperance-Colors and Fonts 各工作区里面的Editor和Syntax Coloring

  4. Side-by-side assembly

    Side-by-side technology is a standard for executable files in Windows 98 Second Edition, Windows 200 ...

  5. Codeforces Round #240 (Div. 2)(A -- D)

    点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...

  6. Android ListView相关 fastScrollEnabled

    1.android:fastScrollEnabled="true" 当数据量比较多的时候,右侧会出现一个可以拉动的滚动条,这样可以很快的拉动,如图:

  7. jmeter 启用gzip压缩——解决测试中web服务器上行流量过大的问题

    最近测了几个前端的项目,发现它们都有一个共同点:应用所在服务器的网卡上行(trans)非常大——经常是 117 MB/S,这已经逼近了千兆网卡的极限了.下面记录下排查和解决过程: 一. jmeter ...

  8. http://jingyan.baidu.com/article/a378c960630e61b329283045.html

    http://jingyan.baidu.com/article/a378c960630e61b329283045.html

  9. BZOJ 1030 文本生成器

    很老的题目了,很早以前学AC自动机的时候就A过一次 今天算是复习啦 我们可以把问题转化成一个给定字符串都没出现的字符串有多少个 我们建立AC自动机,设dp[i][j]表示走了i步当前在j节点上 在DP ...

  10. Android 通过http访问服务器

    目前Android 与服务器交互有两种方式:1.Socket 2. Http : 但由于Http的封装性以及性能比socket要好,所以推荐使用http方式和服务器交互: 通过http访问服务器有三种 ...