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

#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. ecshop 去版权(前台)

    该偏文章模板堂搜集总结,包括ecshop前台版权,ecshop后台版权,一个都不留,干干净净,推荐收藏 一.去掉网页标题 Powered by ECShop 打开includes/lib_main.p ...

  2. laravel多种安装方法

    首先请确保环境为 PHP >= 5.5.9 OpenSSL PHP 扩展 PDO PHP 扩展 Mbstring PHP 扩展 Tokenizer PHP 扩展 方法一: 直接下载安装好的lar ...

  3. ccw-ide

    有bug,会把working set弄乱,整理后能重启一次正常,再次重启又乱了.

  4. adodb.stream对象的方法/属性

    Cancel 方法      使用方法如下      Object.Cancel      说明:取消执行挂起的异步 Execute 或 Open 方法的调用.Close   方法      使用方法 ...

  5. CREATE SCHEMA

    CREATE SCHEMA 创建一个架构,即命名空间,在这个空间中可以进一步定义包含表.视图和权限定义等对象. 语法 CREATE SCHEMA AUTHORIZATION owner    [ &l ...

  6. Mysql-左连接查询条件失效的解决办法

    on 后面不能 接and 要接where 这个条件才能判断成功 判断条件先后顺序,先判断主条件where,再判断条件on 如果是左连接on限制的就是右表,如果不为真则那一行的值为null,where限 ...

  7. switch case多值匹配

    switch case多值匹配一般有两种情况 1.列举(将所有值列举出来) var n= 3;switch (n){    case 1:     case 2:    case 3:         ...

  8. 转: Ant 脚本的结构化设计

    引言 Ant 脚本是由 Apache 提供的一种基于 Java 的构建工具,为 Java 开发人员所熟悉.Java 开发人员使用 Ant 脚本可以很方便地完成 Java 开发过程中常见的如拷贝文件.创 ...

  9. navicat连接oracle时发现 ORA-12737 set CHS16GBK

    oracle安装目录下找到目录:\product\11.2.0\dbhome_1\BIN, 将箭头标注的三个文件(截图中为navicat中的目录,已经测试成功,亲们可以参考)从目录中拷贝纸navica ...

  10. [Python]网络爬虫(四):Opener与Handler的介绍和实例应用

    在开始后面的内容之前,先来解释一下urllib2中的两个个方法:info and geturl urlopen返回的应答对象response(或者HTTPError实例)有两个很有用的方法info() ...