题意:

”平均数“的意思是:最大数和最小数之间的差值为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. nginx+ tomcat集群+动静资源分离

    不知道为什么这个随便删不掉,写了也值显示一半一半不显示, 我把重新写了一遍: nginx + tomcat集群和动静资源分离

  2. [转载]vs2012中使用Spring.NET报错:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常

    学习使用Spring.NET中的时候,写了一个Demo,在运行时报了一个错误:Spring.Context.Support.ContextRegistry 的类型初始值设定项引发异常. 重新整理思绪, ...

  3. Android名词解释

    System Bars.Status Bar.Navigation Bar System Bars-->the Status bars and Navigation bars.

  4. 安装Redis完整过程

    概述    首先报告一下我系统的版本: [root@firefish init.d]# cat /etc/issue 系统版本信息如下: 引用 CentOS release 6.4 (Final) K ...

  5. HDU4627+LCM

    思路是想到了一些 不过愣是没敢写........... /* 题意:给定一个整数n(2 <= n <= 109),满足a+b=n并且[a,b]的最小公倍数最大. */ #include&l ...

  6. java jdbc dbcp连接SQL Server

    使用到的jar: commons-collections-3.1.jar commons-dbcp-1.4.jar commons-pool-1.5.6.jar sqljdbc4.jar dbcp配置 ...

  7. WebViewJavascriptBridge的基本原理

    前言 WebViewJavascriptBridge是支持到iOS6之前的版本的,用于支持native的iOS与javascript交互.如果需要支持到iOS6之前的app,使用它是很不错的.本篇讲讲 ...

  8. Android studio 下的 NDK 配置方法和注意事项

    http://blog.csdn.net/u013598660/article/details/47341963

  9. nginx配置静态文件服务器

    搭建文件服务器 要点就是root目录,会自动指向索引文件 如: index, index.html等 server { client_max_body_size 4G; listen 80; ## l ...

  10. 优化Hoax or what的思考

    在抽取MinHeap的时候,涉及到重载,覆盖,虚函数等,有几点之前没注意到的问题在这里总结下: 1. 覆盖(override)只要是函数同名就会被覆盖,子类指针若调用父类的同名不同参数的函数的话,会在 ...