HDU2088JAVA2
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
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?

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.
have to be moved in order to make all the stacks the same height.
Output a
blank line between each set.
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的更多相关文章
随机推荐
- VLAN间单臂路由访问
实验书上的拓朴图: 注意TRUNK端口和路由器子端口设置,可以承载不同的VLAN标签. 交换机(用2691加交换模块实现的): Building configuration... Current co ...
- [转贴]PHP 开发者应了解的 24 个库
作为一个PHP开发者,现在是一个令人激动的时刻.每天有许许多多有用的库分发出来,在Github上很容易发现和使用这些库.下面是我曾经遇到过最酷的24个库.你最喜欢的库没有在这个列表里面?那就在评论中分 ...
- Android Training精要(二)開啟ActionBar的Overlay模式
在3.0上的實現 <resources> <!-- the theme applied to the application or activity --> <style ...
- linux svn服务器搭建、客户端操作、备份与恢复
Subversion(SVN)是一个开源的版本控制系統,管理着随时间改变的数据.这些数据放置在一个中央资料档案库中,这个档案库很像一个普通的文件服务器,它会记住每一次文件的变动,这样就可以把档案恢复到 ...
- Android之最简单的ImageView加边框方法
转自:http://www.th7.cn/Program/Android/201301/120345.shtml 通常情况下,如果我们要给ImageView加上边框,比如宽为3dp的灰色框,是自己定义 ...
- dev中gridview控件 z
目录:一.客户端常用1.常用API2.聚焦行变更事件3.客户端选择多行4.客户端选择行5. 获取选择的行数目6.单击行时,选中行7.通过checkbox 选择行8.选择所有行9.启动编辑框,Conta ...
- UNion ALL 和 UNION 的区别
UNION: 指定合并多个结果集并将其作为单个结果集返回.ALL: 将全部行并入结果中.其中包括重复行.如果未指定该参数,则删除重复行.
- POJ -- 3140
#include<iostream> #include<cstdio> #include<cstring> #include<string> #defi ...
- 解决Ubuntu下sublime3无法输入中文
参考site: https://github.com/YoungZHU/sublime-imfix 1. 下载sublime-imfix.c 假设下载到了 home(-)目录下 2. 安装c\C++ ...
- Spring框架整合Struts2
1,用Spring架构,及Struts2-spring-plugin插件 导入Spring的dist全部所需的jar包 Struts2的spring插件 struts2-spring-plugin.X ...