HDU 1326 Box of Bricks(水~平均高度求最少移动砖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326
题目大意:
给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同。
解题思路:
找到平均墙的高度(即最后墙的高度),遍历所有墙,如果小于平均墙,则用平均墙减去高度即是要移动的高度,统计所有需要“补”的高度即可。注意输出。
AC Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k=;
while(scanf("%d",&n)!=EOF&&n)
{
int na[n+],cut=;
for(int i=; i<n; i++)
scanf("%d",&na[i]),cut+=na[i];
int avg=cut/n;
cut=;
for(int i=; i<n; i++)
if(na[i]<avg)
cut+=(avg-na[i]);
printf("Set #%d\n",k++);
printf("The minimum number of moves is %d.\n\n",cut);
}
return ;
}
HDU 1326 Box of Bricks(水~平均高度求最少移动砖)的更多相关文章
- HDU 1326 Box of Bricks(思维)
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stac ...
- 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)
本文索引目录: 一.贪心算法的基本思想以及个人理解 二.汽车加油问题的贪心选择性质 三.一道贪心算法题点拨升华贪心思想 四.结对编程情况 一.贪心算法的基本思想以及个人理解: 1.1 基本概念: 首先 ...
- HDOJ 1326 Box of Bricks(简单题)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- 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 ...
- HDOJ(HDU) 2088 Box of Bricks(平均值)
Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...
- [POJ1477]Box of Bricks
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19503 Accepted: 7871 Description Litt ...
- Box of Bricks最小移动砖块数目
Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...
随机推荐
- 长串英文数字强制折行解决办法css
overflow: hidden; white-space: normal; word-warp: break-word; word-break: break-all;/*Only work in I ...
- Django - 获取请求方式
//获取请过来得得请求类型 method = request.method 通过Django 的form 判断用户输入是否通过验证 check = forms.LoginFrom(request.PO ...
- Zookeeper总结
Zookeeper数据模型 zookeeper有一个层级的命名空间,更像一个分布式的文件系统. 唯一的区别就是命名空间中的每一个节点同它关联. ZNodes zookeeper树上的每一个节点被 ...
- Shell命令_for
chmod 755 demo.sh ./demo.sh 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ...
- DTD中的属性类型
<![CDATA[文本内容]]> DTD中的属性类型 全名:character data 在标记CDATA下,所有的标记.实体引用都被忽略,而被XML处理程序一视同仁地当做字符数据看待, ...
- iis 发布静态 html 代码
参考地址: http://jingyan.baidu.com/article/c843ea0b7d0b7177921e4a68.html 操作步骤:1.在当前发布网站中建立虚拟目录 2.点击当前网站 ...
- yii基础应用目录结构
basic/ 应用根目录 composer.json Composer 配置文件, 描述包信息 config/ 包含应用配置及其它配置 console.php 控制台应用配置信息 web.php We ...
- Python 小细节备忘
1. 多行字符串可以通过三个连续的单引号 (”’) 或是双引号 (“”") 来进行标示 >>> a='''a bc def ''' >>> print a ...
- Win7下完全卸载Oracle 11g的步骤
1 右击“计算机”-->管理-->服务和应用程序-->服务,停掉所有Oracle相关的服务(以Oracle打头的,比如OracleDBConsoleorcl). 2 开始--> ...
- bzoj 2005
裸的2D gcd.ans=(Σ(d<=n)phi[d]*(n/d)*(m/d))*2-n*m; #include<iostream> #include<cstdio> # ...