航电ACM step1.2.3 Box of bricks
来源:互联网 发布:大众软件2016 7月 编辑:程序博客网 时间:2024/06/11 20:07
Box of Bricks
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9209 Accepted Submission(s): 2154Problem 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 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 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, 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.
Sample Input
65 2 4 1 7 50
Sample Output
Set #1The minimum number of moves is 5.
航电上的图显示不出来。估计没有多大价值
#include<stdio.h>int main(){int b[1000];int a,n,i,m;int cut=0;while(scanf("%d",&n),n){a=0;int aver,sum=0;for( i=0;i<n;i++){scanf("%d",&b[i]);sum+=b[i];}aver=sum/n;for(i=0;i<n;i++){if(aver>b[i]) a+=aver-b[i];}cut++;printf("Set #%d\n",cut);printf("The minimum number of moves is %d.\n\n",a);}return 0;}
0 0
- 航电ACM step1.2.3 Box of bricks
- 杭电 acm Box of Bricks
- 杭电 HDU ACM 1326 Box of Bricks
- 杭电 2088 Box of Bricks
- 杭电1326-Box of Bricks
- 杭电oj-Box of Bricks
- 问题七十:Box of Bricks (ACM)
- HDU ACM 11 2088 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
- SpringMVC学习笔记(1)之入门篇
- machine-learning第五周 上机作业
- 分布式一致性算法:Paxos (学习总结)
- 搞了一天的stm32f207芯片库函数的I2C问题终于被解决了
- Python 高级特性之生成器表达式
- 航电ACM step1.2.3 Box of bricks
- Android资料之-EditText中的inputType
- Android内存优化之static使用篇
- 用VLFeat库进行k-means聚类(C++ 实现)
- POJ 1032 Parliament
- 常用正则表达式大全
- 关于应用程序加壳后,IAT钩子失效问题的破解
- [转] PHP中读取文件的几个方法
- Hive学习4_Hive on Spark: Getting Started_Common Issues