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 ...
随机推荐
- docker镜像ubuntu封装jdk1.8.0【dockerfile】
github地址:https://github.com/laileman/Docker/Dockerfile/ubuntu-jdk1.8.0_172 1-目录结构 2- dockerfile内容 3- ...
- Django 初试水(三)
在前面的一和二中,分别实现了一些基础的操作,数据库和 Django 自带的管理界面,接下来,主要是创建我们自己的界面(视图). 访问一个地址,对应的服务器直接返回一个视图.这是最常见的交互. 就好比访 ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- Node.js、npm和webpack的安装
1. 前往Node.js官网下载安装程序 2. 一路点击下一步即可 3. 测试是否安装成功 4. 配置npm在安装全局模块时的路径和缓存cache的路径 因为在执行例如npm install webp ...
- 洛谷P1372 又是毕业季I
https://www.luogu.org/problem/P1372 #include<bits/stdc++.h> using namespace std; long long n,k ...
- re正则匹配模块_python
一.re模块 1.模块功能 通过re模块的接口接入正则表达式语言,主要用于匹配字符串. 2.正则表达式元字符以及意义 . 代表任意一个字符(除了换行符\n) ^ 以什么开头 $ 以什么结尾 * 重复匹 ...
- 题解【AcWing176】装满的油箱
题面 一开始拿到这个问题并不好做,于是考虑拆点. 考虑将一个点拆成 \(c+1\) 个,每个点表示(编号,剩余油量). 然后 \(\text{Dijkstra}\) 最短路即可. 每次跑 \(\tex ...
- NEKO's Maze Game
NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms of a ...
- LED Decorative Light Supplier - LED Neon Application: 5 Advantages
In the past 100 years, lighting has gone a long way. LED decorative lighting is now designed to meet ...
- Ubuntu 的apt install 和卸载正确姿势
先说下使用apt installl 安装的包的卸载: apt-get remove: 卸载软件apt-get purge: 卸载软件和配置文件apt-get autoremove: 移除没有使用的依 ...