先算出目标状态,然后拿当前状态与目标状态对比,即可算出答案

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn];
int b[maxn]; int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]); sort(a+,a++n);
int sum=;
for(int i=;i<=n;i++) sum=sum+a[i]; int ave=sum/n;
for(int i=;i<=n;i++) b[i]=ave; int MOD=sum%n;
for(int i=n;i>=n-MOD+;i--) b[i]++; // for(int i=1;i<=n;i++) printf("%d ",b[i]);
int ans=;
for(int i=;i<=n;i++)
ans=ans+max(,a[i]-b[i]); printf("%d\n",ans);
return ;
}

CodeForces 609C Load Balancing的更多相关文章

  1. 609C Load Balancing

    题意: ”平均数“的意思是:最大数和最小数之间的差值为0或1: 先求“平均”数组,再相减. #include<iostream> #include<cstdlib> #incl ...

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

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

  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. 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 ...

  5. CodeForces--609C --Load Balancing(水题)

    Load Balancing Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Subm ...

  6. 【架构】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 ...

  7. UVA 12904 Load Balancing 暴力

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

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

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

  9. [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 ...

随机推荐

  1. 设置标题小图标ico

    在head里添加 <link rel="shortcut icon" href="<%=request.getContextPath()%>/FlatU ...

  2. FileSystemXmlApplicationContext方法的绝对路径问题

    public AgentServer(Socket c,String confDir) { this.client = c; ApplicationContext ac = new FileSyste ...

  3. Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换)

    Android中实现滑动翻页—使用ViewFlipper(dp和px之间进行转换) Android中dp和px之间进行转换 在xml布局文件中,我们既可以设置px,也可以设置dp(或者dip).一般情 ...

  4. ShellExecute快捷键大全

    文件夹,文件,网址可以创建快捷方式,控制面板 中的设置也可以创建快捷方式,下面是快捷方式的命令,使用方法:在桌面或文件夹的空白处点右键,选择新建,快捷方式,在"请键入项目的位置"输 ...

  5. Java BigDecimal Class

    Using BigDecimal to perform precise calculations with floats. BigDecimal is a class type. So declare ...

  6. Learning Java 8 Syntax (Java in a Nutshell 6th)

    Java is using Unicode set Java is case sensitive Comments, C/C++ style abstract, const, final, int, ...

  7. Tiny210编译和烧写u-boot步骤

    当有多个交叉编译器是,不方便设置环境变量时,可以在编译命令中指定交叉编译器,具体如下: make ARCH=arm CROSS_COMPILE=/opt/FriendlyARM/toolschain/ ...

  8. POJ 1365 Prime Land(整数拆分)

    题意:感觉题意不太好懂,题目并不难,就是给一些p和e,p是素数,e是指数,然后把这个数求出来,设为x,然后让我们逆过程输出x-1的素数拆分形式,形式与输入保持一致. 思路:素数打表以后正常拆分即可. ...

  9. Django - 通用视图

    urls.py from . import views ... url(r'^$', views.IndexView.as_view, name="index"), url(r'^ ...

  10. HDU - 5276 YJC tricks time

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5276   Sample Input 99000 0   Sample Output 00:01:30 ...