POJ 1477:Box of Bricks
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 19949 | Accepted: 8029 |
Description
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 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
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.
Source
Southwestern European Regional Contest 1997
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <stdio.h>
int main()
{
int n,i,s,aver,a[51],num,j=0;
while(~scanf("%d", &n))
{
if(n == 0) break;
j++,s = 0,num = 0;
for(i = 0; i < n; i++)
{
scanf("%d", &a[i]);
s+=a[i];
}
aver= s/n;
for(i = 0; i < n; i++)
if(a[i] > aver)
num = num + a[i] - aver;
printf("Set #%d\nThe minimum number of moves is %d.\n\n", j, num);
}
return 0;
}
POJ 1477:Box of Bricks的更多相关文章
- 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 ...
- HDU 2088 Box of Bricks(脑洞)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...
随机推荐
- MySQL主从复制遇到的问题
show slave status\G时,io显示:Slave_IO_State: Connecting 1.检查网络是否畅通,方法:ping主机ip.主机通畅. 2.检查复制用户的账号密码是否正确. ...
- sql server 备份计划
SSMS 1.管理 2.维护计划 3.维护计划向导 或者 1. server 代理 2. 作业 3. 新建作业 备份计划时间尽量选在闲时, 例如午夜
- UVa 1600 Patrol Robot(BFS)
题意: 给定一个n*m的图, 有一个机器人需要从左上角(1,1)到右下角(n,m), 网格中一些格子是空地, 一些格子是障碍, 机器人每次能走4个方向, 但不能连续穿越k(0<= k <= ...
- c++中的三角函数
c++中想求cos或sin: 1.首先得包含头文件,include<math.h> 2.sin(),cos(),中是弧度数,即若是角度a,则应写成cou<<sin(a*pi/1 ...
- JS判断滚动条是否停止滚动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- [luoguP1074] 靶形数独(搜索)
传送门 75分,太菜,不会优化了,吐了. 几点优化. 1.先搜索容易确定的位置 2.从中心往周围搜 3.枚举数字的时候倒序枚举 4.如果没有枚举到的数字都是最优情况的话也不能比当前ans大就剪枝 5. ...
- [luoguP1013] 进制位(搜索)
传送门 纯搜索,无优化! #include <cstdio> #include <cstring> #include <iostream> #include < ...
- 593. Valid Square
Problem statement: Given the coordinates of four points in 2D space, return whether the four points ...
- codeforces 369B
#include<stdio.h>//题没读懂,没做出来 int main() { int n,k,l,r,s,s1,m,a,i; while(scanf("%d%d% ...
- Ajax核心知识(2)
对于Ajax核心的东西需要在进行总结提炼一下: xmlHttp对象. 方法:xml.responseText获取后台传递到前台的数据,经常性的使用var object=xml.responseText ...