609C Load Balancing
题意:
”平均数“的意思是:最大数和最小数之间的差值为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的更多相关文章
- CodeForces 609C Load Balancing
先算出目标状态,然后拿当前状态与目标状态对比,即可算出答案 #include<cstdio> #include<cmath> #include<cstring> # ...
- 【架构】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 ...
- 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 ...
- Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心
C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...
- UVA 12904 Load Balancing 暴力
Load Balancing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/vi ...
- Load Balancing 折半枚举大法好啊
Load Balancing 给出每个学生的学分. 将学生按学分分成四组,使得sigma (sumi-n/4)最小. 算法: 折半枚举 #include <iostrea ...
- [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 ...
- 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 ...
- Network Load Balancing Technical Overview--reference
http://technet.microsoft.com/en-us/library/bb742455.aspx Abstract Network Load Balancing, a clusteri ...
随机推荐
- 一个 XSD 实例
一个 XSD 实例 本节会为您演示如何编写一个 XML Schema.您还将学习到编写 schema 的不同方法. XML 文档 让我们看看这个名为 "shiporder.xml" ...
- Good Bye 2015 A
Problem A:http://codeforces.com/problemset/problem/611/A A. New Year and Days 题意:某人要在2016年收集糖果,有两种不同 ...
- VARCHAR2转换为CLOB碰到ORA-22858错误
近日工作中发现有一张表的字段类型建错了,本应是BLOB类型却被别人建成了VARCHAR2(200),修改时oracle却提示“ORA-22858 invalid alteration of datat ...
- Android 控制ScrollView滚动到底部
scrollView.fullScroll(ScrollView.FOCUS_DOWN);滚动到底部 scrollView.fullScroll(ScrollView.FOCUS_UP);滚动到顶部 ...
- Qt之显示网络图片(可以改成升级模块)
http://blog.csdn.net/u011012932/article/details/50773382
- 关于C的一些理解
关于字符数组和字符指针 关于相互赋值问题一只有疑问,其实是自己搞不清指针和地址的关系.地址可以指向一块内存但是不一定存在于内存,比如字符数组名,数组名是地址,但是不实际存在于内存中,无法修改,而字符指 ...
- nyist 510昂贵的聘礼
/* 好好的图论题啊,最短路的应用,dijkstra算法 */ #include <iostream> using namespace std; const int INF=100000; ...
- Upload/download/UrlConnection/URL
文件上传的核心点 1:用<input type=”file”/> 来声明一个文件域.File:_____ <浏览>. 2:必须要使用post方式的表单. 3:必须设置表单的类型 ...
- 【转】Android设计中的.9.png
来源:http://isux.tencent.com/android-ui-9-png.html Android设计中的.9.png 注意:当使用9.png做TextView背景时,一定要设置内容区域 ...
- Factorial
Factorial 计算阶乘 In mathematics, the factorial of a non-negative integer n, denoted by n!, is the pro ...