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的更多相关文章
随机推荐
- Android使用pull解析xml
一.理论准备 Pull解析器的运行方式与 SAX 解析器相似.它提供了类似的事件,如:开始元素和结束元素事件,使用parser.next()可以进入下一个元素并触发相应事件.跟SAX不同的是, ...
- JAVA 抛出与声明异常
在编程过程中,我们往往会遇到这种情况,在当前环境中无法解决,比如用户传入的参数错误,IO设备问题等.此时,就要从当前环境中抛出异常提交给上级来处理. 在JAVA语言中,使用throw关键字来抛出异常. ...
- bzoj1570
购买的机票限制和数据范围很容易想到是网络流不难想到每个城市按时刻拆点,这也是一个经典模型由于时间不会太大,我们穷举时间,不断在残留网络上建图,跑最大流直至总流量为k即可 ; type node=rec ...
- bzoj3172
这里学习AC自动机其实对KMP和trie掌握好了之后很容易扩展成AC自动机的这里运用了一个性质由失配指针反向可以建成一棵fail树x串在y串中的出现的次数即为在fail树上以x结尾节点为根的子树中有多 ...
- 拷贝出你GAC里面的DLL文件
转:http://blog.sina.com.cn/s/blog_573be9bc0100ht65.html 早上和同事探讨如何从GAC中拷贝已经部署的DLL文件的时候,除了以前熟悉的命令行拷贝方法, ...
- Maven学习:常用mvn命令
转自:http://blog.csdn.net/lfsfxy9/article/details/12200915 Maven 在线: <span style="font-family: ...
- 浅谈pageobject模式
先来看两段代码 代码1: package com.zlshuo.selenium.nonaming.pageobject; /** * @author leshuo * @version 2014年5 ...
- AppStore IAP 客户端校验代码
-(BOOL)putStringToItunes:(SKPaymentTransaction*)transaction { NSData * iapData = transaction.transac ...
- Unity给力插件之ShaderForge(二)
直接上实例: 一.自定义光照: 效果图(白色点光源照射时) 图片及参数 节点编辑 备注: 1.append为追加:两个一维数值合并为一个二维数值,一个二维数值与一个一维数值合并为一个三维数值,以此类推 ...
- JavaScript高级程序设计26.pdf
DOM操作技术 动态脚本 指得是页面加载时不存在,但将来的某一时刻通过修改DOM动态添加的脚本,跟操作HTML元素一样,创建动态脚本也有2种方式:插入外部文件和直接插入JavaScript代码 var ...