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的更多相关文章
随机推荐
- BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
Description 最近,奶牛们热衷于把金币包在面粉里,然后把它们烤成馅饼.第i块馅饼中含有Ni(1<=Ni<=25)块金币,并且,这个数字被醒目地标记在馅饼表面. 奶牛们把所有烤好的 ...
- 【HDU 1828】 Picture (矩阵周长并,线段树,扫描法)
[题目] Picture Problem Description A number of rectangular posters, photographs and other pictures of ...
- Gson把json串转换成java实体对象
Gson把json串转换成java实体对象的方法如下: 1.首先导入Gson的jar包,网上可以下载. java实体对象如下: public class Model { private double ...
- Android的那些轮子
整个AOSP代码,包天包地,从kernel,libc,gui,net……简直包括了绝大多普通程序员职业生涯涉及的整个领域.其实,开源界早已经遇到并且解决了Android的很多问题,不过google讨厌 ...
- 协助ScriptCase7.1做些汉化矫正工作
之前帮助Script.net做了一部分网站的汉化工作,不过我对ScriptCase自己做的网站不满意,对其汉化网站更是不满意. ScriptCase7出来之后,比较让人头疼的就是汉化的问题,较之v6, ...
- [置顶] Objective-C,/,ios,/iphone开发基础:分类(category,又称类别)
在c++中我们可以多继承来实现代码复用和封装使程序更加简练.在objective-c中只能单继承,不能多继承,那么除了协议protocol之外,我们可以实现类似多继承的一个方法就是,分类(catego ...
- C#面向对象——成员变量及封装
namespace 面向对象5_22 { class Animal { private string _Type; public string Type { get { return _Type; } ...
- 一起啃PRML - 1.2.2 Expectations and covariances 期望和协方差
一起啃PRML - 1.2.2 Expectations and covariances 期望和协方差 @copyright 转载请注明出处 http://www.cnblogs.com/chxer/ ...
- CSS中背景图片定位方法
转自:http://www.ruanyifeng.com/blog/2008/05/css_background_image_positioning.html 作者: 阮一峰 日期: 2008年5月 ...
- HDU-2552 三足鼎立
三足鼎立 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...