HDU 2088 Box of Bricks
来源:互联网 发布:辐射4 捏脸数据 编辑:程序博客网 时间:2024/05/21 01:29
http://acm.hdu.edu.cn/showproblem.php?pid=2088
Box of Bricks
Time Limit: 1000/1000 MS(Java/Others)
Total Submission(s):5277
Problem Description
Little Bob likes playing with his box ofbricks. He puts the bricks one upon another and builds stacks ofdifferent height. “Look, I've built a wall!”, he tells his oldersister Alice. “Nah, you should make all stacks the same height.Then you would have a real wall.”, she retorts. After a littleconsideration, Bob sees that she is right. So he sets out torearrange the bricks, one by one, such that all stacks are the sameheight afterwards. But since Bob is lazy he wants to do this withthe 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 Bobhas built. The next line contains n numbers, the heights hi of then stacks. You may assume 1≤n≤50 and 1≤hi≤100.
The total number of bricks will be divisible by the number ofstacks. Thus, it is always possible to rearrange the bricks suchthat all stacks have the same height.
The input is terminated by a set starting with n = 0. This setshould not be processed.
The total number of bricks will be divisible by the number ofstacks. Thus, it is always possible to rearrange the bricks suchthat all stacks have the same height.
The input is terminated by a set starting with n = 0. This setshould not be processed.
Output
For each set, print the minimum numberof bricks that have to be moved in order to make all the stacks thesame height.
Output a blank line between each set.
Output a blank line between each set.
Sample Input
6 5 2 4 1 75 0
Sample Output
5
Author
qianneng
Source
冬练三九之二
Recommend
lcy
分析:简单题,轻轻地AC之。。
代码如下:
#include<stdio.h>
#include<string.h>
#include<math.h>
int abs(int x)
{
return x>0?x:-x;
}
int main()
{
intn,i,hei,ans;
intw[51];
intcount=0;
while(scanf("%d",&n),n)
{
if(count!=0) printf("\n");
ans=hei=0;
for(i=0;i<n;i++)
{
scanf("%d",&w[i]);
hei+=w[i];
}
hei=hei/n;
for(i=0;i<n;i++)
ans+=abs(hei-w[i]);
printf("%d\n",ans/2);
count++;
}
return 0;
}
#include<string.h>
#include<math.h>
int abs(int x)
{
}
int main()
{
}
阅读全文
0 0
- HDU 2088 Box of Bricks
- HDU 1326 Box of Bricks
- Box of Bricks
- HDU 1010 Tempter of the Bone
- hdu 1692 Destroy the Well of Lif…
- HDU 1242 Rescue
-  
- poj 1442 Black Box
- poj 1442 Black Box
- POJ 2160 BOX
-
- HDU 2401 Baskets of Gold Coins
- HDU 1202 The calculation of GPA
- HDOJ 1010 Tempter of the Bone
- resource is out of sync with t…
- ZZULI_SummerPractice(3) HDU 1…
- HDU 1579 Function Run Fun
- HDU 1405 The Last Practice
- HDU 2103 Family planning
- OpenStack Tacker介绍
- 卡方检验原理及应用
- HDU 2098 分拆素数和
- HDU 2093 考试排名
- HDU 2088 Box of Bricks
- 一个web项目web.xml的配置中<context-param>配置作用
- HDU 2078 复习时间
- HDU 2076 夹角有多大(题目已修改,…
- POJ 1144 Network 裸割点
- 页面效果
- HDU 2073 无限的路
- HDU 2061 Treasure the new start,…
- Vue.js-----轻量高效的MVVM框架(九、组件利用Props传递数据)