Box of Bricks 2088
来源:互联网 发布:虚拟主机怎么解析域名 编辑:程序博客网 时间:2024/05/20 11:23
Problem Description
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds
stacks of different height. “Look, I've built a wall!”, he tells his older sister Alice. “Nah, you should
make all stacks the same height. Then you would have a real wall.”, she retorts. After a little
consideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one,
such that all stacks are the same height afterwards. But since Bob is lazy he wants to do
this with the minimum number of bricks moved. Can you help?
Input
The input consists of several data sets. Each set begins with a line containing the number n of
stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may
assume 1≤n≤50 and 1≤hi≤100.
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange
The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange
the bricks such that all stacks have the same height.
The input is terminated by a set starting with n = 0. This set should not be processed.
The input is terminated by a set starting with n = 0. This set should not be processed.
Output
For each set, print the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line between each set.
Output a blank line between each set.
Sample Input
65 2 4 1 7 50
Sample Output
5#include <cstdio>#include <vector>#include <algorithm>#include <numeric>int main(int argc, const char* argv[]){ int n = 0; bool bFlag = true; while (scanf("%d", &n) != EOF && n > 0) { std::vector<int> vec; int nTemp = 0; while (n--) { scanf("%d", &nTemp); vec.push_back(nTemp); } int nSum = accumulate(vec.begin(), vec.end(), 0); int nAve = nSum / vec.size(); int nMin = 0; for (int i=0; i<vec.size(); ++i) { if (vec[i] > nAve) { nMin += vec[i] - nAve; } } if (bFlag) { printf("%d\n", nMin); bFlag = false; } else { printf("\n%d\n", nMin); } } return 0;}
0 0
- Box of Bricks 2088
- 2088 Box of Bricks
- Box of Bricks 2088
- HDU 2088 Box of Bricks
- HDOJ 2088 Box of Bricks
- HDU 2088 Box of Bricks
- HDOJ 2088 Box of Bricks
- hdu 2088 Box of Bricks
- HDU#2088: Box of Bricks
- HDU 2088 Box of Bricks
- HDU - 2088 - Box of Bricks
- HDOJ 2088 Box of Bricks
- hdu 2088 Box of Bricks(water~)
- 杭电 2088 Box of Bricks
- HDOJ 【C】 2088 Box of Bricks
- HDU—— 2088 Box of Bricks
- HDOJ(HDU) 2088 Box of Bricks(平均值)
- HDU ACM 11 2088 Box of Bricks
- 190亿美元的WhatsApp背后的小众编程语言:Erlang
- BioPerl:批量下载序列
- android数据存储_外部存储
- 获取汉字首字母2
- [HDOJ 1558] Segment set [线段相交+并查集]
- Box of Bricks 2088
- dom4j读写xml文件
- 如何优化Cocos2d-X游戏的内存
- getHibernateTemplate()(Spring中常用的hql查询方法)
- 在php中,javascript的使用(包含了php变量)
- 【数据结构】bitset
- 数据库设计的14个技巧(转)
- 数据结构之并查集
- 内网映射外网之80端口映射和全端口映射的实现和发布网站应用、外网访问内网