HDU 2088 Box of Bricks(脑洞)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=2088
Box of Bricks
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20219 Accepted Submission(s): 6473

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 a blank line between each set.
5 2 4 1 7 5
0
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max_v 50
int a[max_v];
int main()
{
int n,k=;
while(~scanf("%d",&n))
{
if(n==)
break;
if(k)
printf("\n");//注意输出格式,最后一个测试不能有空行
int sum=;
for(int i=; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
sum/=n;//平均
int c=;
for(int i=; i<n; i++)
{
if(a[i]<sum)//小于平均的栈其差多少的和就是需要移动的总数
c+=(sum-a[i]);
}
printf("%d\n",c);
k++;
}
return ;
}
HDU 2088 Box of Bricks(脑洞)的更多相关文章
- 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)
本文索引目录: 一.贪心算法的基本思想以及个人理解 二.汽车加油问题的贪心选择性质 三.一道贪心算法题点拨升华贪心思想 四.结对编程情况 一.贪心算法的基本思想以及个人理解: 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 ...
- HDU 1326 Box of Bricks(思维)
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stac ...
- 杭电 2088 Box of Bricks
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2088 解题思路:一堆高度不同的砖块,需要把它们砌成一堵墙,即每一堆砖的高度相同(即砖的总数除以砖的堆数 ...
- 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 ...
- 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 ...
随机推荐
- vcfc之zk+postsql+keystore(cassandra)框架分析
vcfc框架总结: 1 一. bus和keystore是如何协调处理的,什么样的问题是处理不了的? 1. 如果在备重启的过程中,主处理了某个时间1,备机如果同步数据呢? 二 .数据可靠性和一致性分析 ...
- mysql 笔记3
--建库create database dsdb DEFAULT CHARACTER set utf8 collate utf8_general_ci;/*删除数据库drop DATABASE 数据库 ...
- 如何让div覆盖canvas元素
第一步 请让该div和canvas同样处于同一画布,都用position:absolute; 然后设置canvas的z-index="-1",是的,你没看错 然后把要覆盖canva ...
- (C# 正则表达式)判断匹配, 提取字符串或数值
string s = "if ( \"ch\" == \"os\" ) "; string pattern = @"if\s*\( ...
- QML Delegate中访问该持有者的方式 附加属性(转载)
http://blog.csdn.net/yuxiaohen/article/details/17226971 用法很奇葩记录一下,实测可以,用于弱化delegate与持有者的依赖 delegat ...
- 如何为运行的 ARM Linux 启用 LAD2.3 版本的诊断扩展
Linux Azure Diagnostic (LAD) 扩展现在已经发布了 3.0 版本,但在 Azure 中国区,目前可用的最新版本还是 2.3. 虽然 Azure 门户提供了简单的操作版本为 L ...
- POI读取xls和xlsx
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import ...
- js 数据格式化
//金额增加千分号formatPrice(123456.78) = 123,456.78 function formatPrice(val) { var parts = val.toString(). ...
- Day01——Python简介
一.Python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC ...
- 一段SQL代码
begin transaction set quoted_identifier on set arithabort on set numeric_roundabort off set concat_n ...