HDU 1326 Box of Bricks(思维)
InputThe 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.
OutputFor each set, first print the number of the set, as shown in the sample output. Then print the line ``The minimum number of moves is k.'', where k is the minimum number of bricks that have to be moved in order to make all the stacks the same height.
Output a blank line after each set.
Sample Input
6
5 2 4 1 7 5
0
Sample Output
Set #1
The minimum number of moves is 5. 题意:使高度相同的最少移动次数
代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int k=1;
while(scan.hasNext()){
int n=scan.nextInt();
if(n==0) break;
int a[]=new int[n];
int sum=0;
for(int i=0;i<n;i++) {
a[i]=scan.nextInt();
sum+=a[i];
}
int avg=sum/n,min=0;
for(int i=0;i<n;i++){
if(a[i]<avg) min+=(avg-a[i]);
}
System.out.println("Set #"+(k++));
System.out.println("The minimum number of moves is "+min+".");
System.out.println();
}
}
}
HDU 1326 Box of Bricks(思维)的更多相关文章
- HDU 1326 Box of Bricks(水~平均高度求最少移动砖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 2088 Box of Bricks
http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...
- HDU 2088 Box of Bricks(脑洞)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...
- 『嗨威说』算法设计与分析 - 贪心算法思想小结(HDU 2088 Box of Bricks)
本文索引目录: 一.贪心算法的基本思想以及个人理解 二.汽车加油问题的贪心选择性质 三.一道贪心算法题点拨升华贪心思想 四.结对编程情况 一.贪心算法的基本思想以及个人理解: 1.1 基本概念: 首先 ...
- HDOJ(HDU) 2088 Box of Bricks(平均值)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- Box of Bricks最小移动砖块数目
Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...
- [POJ1477]Box of Bricks
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19503 Accepted: 7871 Description Litt ...
随机推荐
- TCP/IP协议和socket
1.传输层基于tcp协议的三次握手和四次挥手? 传输层有两种数据传输协议,分别为TCP协议和UDP协议,其中TCP协议为可靠传输,数据包没有长度设置,理论可以无限长,而UDP协议为不可靠传输,报头一共 ...
- 菜得一P!
什么时候才能改变粗心大意的坏毛病!太吃亏了...
- xmind修改默认配置
XMIND使用过程中,输入英文字符的时候,第1.2层级的英文字母总是默认大写,手动修改很繁琐.默认字体,想切换成其他类型,也是要手动一个个去修改. 网上找了下相关的问题,找到一些解决办法,整理到文档中 ...
- Vue中封装axios
参考: https://www.jianshu.com/p/7a9fbcbb1114 https://www.cnblogs.com/dreamcc/p/10752604.html 一.安装axios ...
- TD - 输入框
模板1:TD - 普通输入框 <input dojoType="bootstrap.form.ValidationTextBox" dojoAttachPoint=" ...
- 占位 LR
占位 LR include: LR403
- Spring框架详解介绍-基本使用方法
1.Spring框架-控制反转(IOC) 2.Spring框架-面向切面编程(AOP) 3.Spring 内置的JdbcTemplate(Spring-JDBC) Spring框架-控制反转(IOC) ...
- 关于vue :style 的几种使用方式
:style的使用 一 ,最通用的写法 <p :style="{fontFamily:arr.conFontFamily,color:arr.conFontColor,backgrou ...
- OpenTLD相关资料
这是一位来自奥地利的博士生的博客 他的介绍如下: I am a PhD student at the Safety and Security Department of the Austrian In ...
- word中去除所有table键
1.打开word---文件---选项---显示,不勾选制表符 2.选择需要的文本,按[CTRL+H]查找替换, 3.将鼠标定位至“查找内容”,点击“特殊格式-制表符”,然后出现^t,在“替换为”中输入 ...