zoj 1251 Box of Bricks
Box of Bricks
Time Limit: 2 Seconds Memory Limit: 65536 KB
Little Bob likes playing with his box of bricks. He 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 con- sideration, 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?
Input
The 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.
Output
For 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.
注意格式。
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
int n, t, sum, cnt, average, k = ;
vector<int> v;
while(cin >> n){
if(n == )
break;
v.clear();
sum = ;
cnt = ;
for(int i = ; i < n; i++){
cin >> t;
v.push_back(t);
sum += t;
}
average = sum / v.size();
for(int i = ; i < v.size(); i++){
if(v[i] > average){
cnt += (v[i] - average);
}
}
cout << "Set #" << k++ << endl;
cout << "The minimum number of moves is " << cnt << "." << endl;
cout << endl;
}
//system("pause");
return ;
}
zoj 1251 Box of Bricks的更多相关文章
- ZOJ Problem Set - 1251 Box of Bricks
这道题简单的翻译成纯数学语言就是给你n个数字,每次运算只能是加1或者减1,问经过最短几步可以使得n个数字相等 由于题目限定了n个数字一定有平均数,所以求出avg,将所有比其大的数字或者比其小的数字的差 ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 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 ...
- 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 ...
- 591 - Box of Bricks
Box of Bricks Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...
- Box of Bricks
Box of Bricks Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- HDU 2088 Box of Bricks
http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...
随机推荐
- HBase表结构设计--练习篇
一.表结构操作 1.建立一个表scores,有两个列族grad和course [hadoop@weekend01 ~]$ hbase shell hbase(main):006:0> creat ...
- SASS @mixin 遇到的坑
@mixin borderTop($size:1px,$type:solid,$color:red){ border-top:$size $type $color; } .border_top{ @i ...
- idea web项目热部署
之前用idea写web项目的时候,一直都是改一点东西就要重启一下,很烦.今天终于忍受不了百度了一下idea怎么热部署web项目. 在此记录下. 第一步 编辑tomcat配置 第二步 选择打包的项目,并 ...
- JAVA 运用流编程实现简单的"记事本"功能
一.概要 1.功能介绍 2.实现的思路及步骤代码 3.完整代码 二.功能 运用IO流和Swing实现简单的记事本功能(打开.保存.退出) 三.思路及实现步骤 1.在构造函数中画出操作界面 //创建jt ...
- java 获取ip地址
1.使用WIFI 首先设置用户权限 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"& ...
- Android学习笔记(十六) ContentProvider
1.相关概念 ContentProvider:不同应用程序之间进行数据交换的标准API:程序“暴露”数据的方法. ContentResolver:一个程序访问另一个程序被“暴露”的数据的方法. Uri ...
- iOS开发-Runtime详解
iOS开发-Runtime详解 简介 Runtime 又叫运行时,是一套底层的 C 语言 API,其为 iOS 内部的核心之一,我们平时编写的 OC 代码,底层都是基于它来实现的.比如: [recei ...
- 【HEVC帧间预测论文】P1.2 An Efficient Inter Mode Decision Approach for H.264 Video Codin
参考:An Efficient Inter Mode Decision Approach for H.264 Video Coding <HEVC标准介绍.HEVC帧间预测论文笔记>系列博 ...
- swift Equatable 的缺省实现
Starting from Swift 4.1, all you have to is to conform to the Equatable protocol without the need of ...
- Android系统固件定制方式
target_product.mkAndroid系统在构建关于某种产品的固件时,一般会根据特定于该产品的具体target_product.mk来配置生成整个Android系统./target_prod ...