Box of Bricks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 19949   Accepted: 8029

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

Sample Output

Set #1
The minimum number of moves is 5.

Source

Southwestern European Regional Contest 1997

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include <stdio.h>
int main()
{
int n,i,s,aver,a[51],num,j=0;
while(~scanf("%d", &n))
{
if(n == 0) break;
j++,s = 0,num = 0;
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
s+=a[i];
}
aver= s/n;
for(i = 0; i < n; i++)
if(a[i] > aver)
num = num + a[i] - aver;
printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, num);
}
return 0;
}

最新文章

  1. 浅析匿名函数、lambda表达式、闭包(closure)区别与作用
  2. 安装memcache扩展
  3. 关于PHP堆栈与列队
  4. IOS开发之——CocoaPods安装和使用 OC和swift通吃
  5. CG基础教程-陈惟老师十二讲笔记
  6. C链表操作
  7. leetcode第一刷_Triangle
  8. cf448A Rewards
  9. UESTC_贪吃蛇 CDOJ 709
  10. 【学习笔记】锋利的jQuery(三)事件和动画
  11. java_web学习(8)会话与状态管
  12. [bzoj2462] [BeiJing2011]矩阵模板
  13. Spring cloud整体框架
  14. 【转】线段树完全版~by NotOnlySuccess
  15. centos设置路由route
  16. Z 字形变换
  17. WebSocket异步通讯,实时返回数据实例
  18. 网站被植入Webshell的解决方案
  19. [CF1019D]Large Triangle[极角排序+二分]
  20. POJ - 1101 The Game dfs

热门文章

  1. 计算几何——认识基本object:点、线、面 。
  2. HDU - 2058 The sum problem(思路题)
  3. 微信小程序 设置计时器(setInterval)、清除计时器(clearInterval)
  4. 【转】vfork 和 fork的区别
  5. list嵌套,int与str的用法,replace
  6. C++ 类 直接定义对象与new对象的区别
  7. poj 1088 滑雪 DP(dfs的记忆化搜索)
  8. java-得到字符串中出现次数最最多的字符,并打印出字符以及出现次数
  9. 2018/2/14 x-pack的学习
  10. 【HDOJ6148】Valley Numer(数位DP)