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 ...
随机推荐
- State Management
Samza的task可以把数据进行本地存储,并且对这些数据进行丰富的查询. 比较SQL中的select ... where...并不需要保存状态.但是aggregation和join就需要存储ro ...
- POJ 2193 Lenny's Lucky Lotto Lists (DP)
题目链接 题意 : 给你两个数N和M,让你从1到M中找N个数组成一个序列,这个序列需要满足的条件是后一个数要大于前一个数的两倍,问这样的序列有多少,输出. 思路 : dp[i][j]代表着长度为 i ...
- NEERC 2014, Eastern subregional contest
最近做的一场比赛,把自己负责过的题目记一下好了. Problem B URAL 2013 Neither shaken nor stirred 题意:一个有向图,每个结点一个非负值,可以转移到其他结点 ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-005-Applying LDAP-backed authentication
一. 1.This method is the LDAP analog to jdbcAuthentication() @Override protected void configure(Aut ...
- cache设计,以及多核造成的不一致性以及解决方案
http://www.360doc.com/content/11/1013/00/1317564_155625188.shtml http://blog.csdn.net/muxiqingyang/a ...
- strcpy函数的C/C++实现
2013-07-05 14:07:49 本函数给出了几种strcpy与strncpy的实现,有ugly implementation,也有good implementation.并参考标准库中的imp ...
- PHP的(Thread Safe与Non Thread Safe)
在安装xdebug到时候你会有有TS和NTS版本的选择,在以前还有VC6和VC9的版本.如果你没有根据你目前的服务器的状况选择对应的版本的话,那么xdebug是安装不成功的. 一.如何选择 php5. ...
- 函数buf_LRU_get_free_only
/******************************************************************//** Returns a free block from th ...
- UVa 11572 (滑动窗口) Unique Snowflakes
滑动窗口挺有意思的,如果符合条件右端点一直向前走,不符合的话,左端点向前走. #include <bits/stdc++.h> using namespace std; set<in ...
- I.MX6 PMU MMPF0100 driver porting
/************************************************************************** * I.MX6 MMPF0100 driver ...