Box of Bricks

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14836    Accepted Submission(s):
4912

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 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
6
5 2 4 1 7 5
0
 
Sample Output
5

import java.util.Scanner;
public class Main2088 {
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int flag=0;
while(cin.hasNext()){
int n=cin.nextInt();
if(n==0)
break;
if(flag==1)
System.out.println();
int []a=new int [n];
int sum=0;
for(int i=0;i<n;i++){
a[i]=cin.nextInt();
sum+=a[i];
}
sum=sum/n;
int s=0;
for(int i=0;i<n;i++){
if(a[i]>sum){
s+=(a[i]-sum);
}
}
System.out.println(s);
flag=1;

}
}

}

这是一个水题,注意一下格式的输出就行。

HDU2088JAVA2的更多相关文章

随机推荐

  1. 【HDU 2853】Assignment (KM)

    Assignment Problem Description Last year a terrible earthquake attacked Sichuan province. About 300, ...

  2. PEP Index > PEP 339 -- Design of the CPython Compiler 译文

    http://www.python.org/dev/peps/pep-0339/ PEP: 339 标题: CPython的编译器设计 版本: 425fc5598ee8 最后修改: 2011-01-1 ...

  3. [C# 网络编程系列]专题九:实现类似QQ的即时通信程序

    转自:http://www.cnblogs.com/zhili/archive/2012/09/23/2666987.html 引言: 前面专题中介绍了UDP.TCP和P2P编程,并且通过一些小的示例 ...

  4. python 零散记录(三) 格式化字符串 字符串相关方法

    使用 % 符号格式化字符串: """常用转换说明符:""" #%s: 按照str()方式转换 #%r: 按照repr()方式转换 #%d: ...

  5. leetcode旋转数组查找 二分查找的变形

    http://blog.csdn.net/pickless/article/details/9191075 Suppose a sorted array is rotated at some pivo ...

  6. bzoj 1036 [ZJOI2008]树的统计Count(树链剖分,线段树)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 10677  Solved: 4313[Submit ...

  7. jQuery技术内幕预览版.pdf1

    第一章 总体构架 jQuery模块可以分为3部分:入口模块.底层支持模块和功能模块 浏览器功能测试模块提供了针对不同浏览器功能和bug的测试结果,其它模块基于测试结果解决浏览器之间的兼容性问题 回调函 ...

  8. Poj 2528-Mayor's posters 线段切割

      题目:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS   Memory Limit: 65536K Total ...

  9. linux设置LD_LIBRARY_PATH变量

    在 Linux 下,如果你写好了自己的动态链接库,需要在其它程序里调用,则需要让这些程序能找到这些动态链接库.如果设置不对,会出现类似如下的错误: test: error while loading ...

  10. PHP中使用函数array_merge()合并数组

    如果明白数组其实就是map的话,我想你就会明白array_merge为什么要这么实现了 PHP中合并数组分成两种情况 1.如果这两个数组中有相同的字符串键名: <?php header('Con ...