看到这题是我的想法就是肯定跟平均值有关但是接下来就不知道怎么做了

看完大神的正解数之后,原来发现是这么简单,但是就是不知道为啥一定是平均值和平均值加1,而不是平均值和平均值减1;

好啦下面就贴出大神的代码吧:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std; int a[100005]; int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+1+n);
long long sum = 0;
for(int i=1;i<=n;i++)
sum+=a[i];
int p = sum / n;
int n1 = n - sum%n;
int ans = 0;
for(int i=1;i<=n1;i++)
{
if(p<=a[i])break;
ans+=p-a[i];
}
for(int i=n1+1;i<=n;i++)
{
if(a[i]>p)break;
ans+=p+1-a[i];
}
printf("%d\n",ans);
}

CodeForce---Educational Codeforces Round 3 Load Balancing 正题的更多相关文章

  1. Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes

    B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  3. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  4. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  5. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  6. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  7. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  8. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. lintcode:First Missing Positive 丢失的第一个正整数

    题目 丢失的第一个正整数 给出一个无序的整数数组,找出其中没有出现的最小正整数. 样例 如果给出 [1,2,0], return 3 如果给出 [3,4,-1,1], return 2 挑战 只允许时 ...

  2. 保障视频4G传输的流畅性,海康威视摄像头相关设置

    我们目前的rtsp视频解决方案如下: 摄像头<---------->NVR(通过4G上传)<---------->easydarwin<---------->自己的 ...

  3. 一个不错的log4j.properties例子

    # Set root logger level to WARN and append to stdout #在开发环境下日志级别要设置成DEBUG,生产环境设置成info或error log4j.ro ...

  4. python处理Excel

    Python中一般使用xlrd库来读取Excel文件,使用xlwt库来生成Excel文件,使用xlutils库复制和修改Excel文件.这三个库只支持到Excel2003. python-excel主 ...

  5. 深度神经网络如何看待你,论自拍What a Deep Neural Network thinks about your #selfie

    Convolutional Neural Networks are great: they recognize things, places and people in your personal p ...

  6. UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树

    Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 65535/32768K (Java/ ...

  7. ctrlsf插件

    输入CtrlSF pattern <dir>来搜索 想要搜索当前文件,用CtrlSF pattern %p(或者C-R %) 在结果界面,p键预览,回车进入闭关内关闭搜索结果框,t键打开一 ...

  8. IOS代码

    //// MJViewController.m// UITableView-编辑模式//// Created by mj on 13-4-11.// Copyright (c) 2013年 itcas ...

  9. OracleApps Dropship 流程

    做的一个Dropship流程的实录(包括流程期间遇到问题的解决)What are the advantages of Drop Shipment Orders?These are the benefi ...

  10. Java开发之单例设计模式

    设计模式之单例模式: 一.单例模式实现特点:①单例类在整个应用程序中只能有一个实例(通过私有无参构造器实现):②单例类必须自己创建这个实例并且可供其他对象访问(通过静态公开的访问权限修饰的getIns ...