题意:

”平均数“的意思是:最大数和最小数之间的差值为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. mv 的使用

    Linux下目录的合并以及文件的覆盖案例 功能说明:将源文件重命名为目标文件,或将源文件移动至指定目录. 用法:mv [选项]... [-T] 源文件 目标文件 或:mv [选项]... 源文件... ...

  2. Binary search for the first element greater than target

    We all know how to search through an array for an element whose value equals the target value, but h ...

  3. Unity3D NGUI自适应屏幕分辨率(2014/4/17更新)

    原地址:http://blog.csdn.net/asd237241291/article/details/8126619 原创文章如需转载请注明:转载自 脱莫柔Unity3D学习之旅 本文链接地址: ...

  4. fiddler 插件开发

    本文主要讲解使用.net C#语言开发Fiddler插件. 1.在Fiddler 会话列表中添加自定义列 使用FiddlerApplication.UI.lvSessions.AddBoundColu ...

  5. c/c++中一些高级函数的使用

    setvbuf 函数名: setvbuf 功 能: 把缓冲区与流相关 用 法: int setvbuf(FILE *stream, char *buf, int type, unsigned size ...

  6. SSL构建单双向https认证

    1.  SSL基本介绍 我们常常在使用网上银行时看到的连接都是以“https”开始的,那么这个https是什么呢?这其实是表示目前连接使用了SSL进加密,能保证客户端到服务器端的通信都在被保护起来,那 ...

  7. 97. Interleaving String

    题目: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given: ...

  8. 函数(Functions)

      概念: 下面是蛮经典的解释: What Good are Functions? You might have considered the situation where you would li ...

  9. cdev[典]

    linux-2.6.22/include/linux/cdev.hstruct cdev {   struct kobject kobj;          // 每个 cdev 都是一个 kobje ...

  10. GCC编译C程序源代码

    编译简单的 C 程序 C 语言经典的入门例子是 Hello World,下面是一示例代码: #include <stdio.h>  int main(void)  {     printf ...