U-Box of Bricks
来源:互联网 发布:电子音乐推荐 知乎 编辑:程序博客网 时间:2024/06/09 23:54
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 con- sideration, 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 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.
Output
For each set, first print the number of the set, as shown in the sample output. Then print the line “The minimum number of moves is k.”, where k is the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line after each set.
Sample Input
6
5 2 4 1 7 5
0
打砖块,跟平均值有关系,取平均值然后补过来,就那个意思
#include<iostream>using namespace std;int a[55];int main(){ int n,i,j,t=0; while(cin>>n&&n) { int ave=0; t++; j=0; for(i=1;i<=n;i++) { cin>>a[i]; ave+=a[i]; } ave=ave/n; for(i=1;i<=n;i++) { if(a[i]>ave) j+=a[i]-ave; } cout<<"Set #"<<t<<endl; cout<<"The minimum number of moves is "<<j<<"."<<endl<<endl; } return 0;}
- U-Box of Bricks
- U-Box of Bricks
- Box of Bricks
- 1477 Box of Bricks
- 1477:Box of Bricks
- 1477 Box of Bricks
- 591 - Box of Bricks
- HDOJ1326 Box of Bricks
- HDU1326:Box of Bricks
- 591 - Box of Bricks
- 591 - Box of Bricks
- UVA591- Box of Bricks
- BNU Box of Bricks
- Box of Bricks
- hdu1326 Box of Bricks
- Box of Bricks
- Box of Bricks
- Box of Bricks
- 学习Javascript闭包(Closure),从外部读取局部变量
- 如何给SNMP Trap通道加上同步机制
- Bootstrap学习之四:表单
- maven 找不到符号 或者总是报编译错误
- 动态范围规划(调整)Dynamic Range Control的一些心得(一)
- U-Box of Bricks
- cocoapods安装以及使用(图文详解)
- [一起学Hive]之二–Hive函数大全-完整版
- 成功移植 SSH 服务到 ARM 开发板上
- 优先级反转
- JAVA 常用的加密算法之对称加密DES、3DES和AES
- 输入一行 string (带空格)
- 利用静态内部类来实现builder模式
- fedora21配置tftp服务器