数学D - Box of Bricks
来源:互联网 发布:怎么申请成为淘宝达人 编辑:程序博客网 时间:2024/05/29 17:50
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 numbern of stacks Bob has built. The next line contains n numbers, the heightshi of the n stacks. You may assume and.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
65 2 4 1 7 50
Sample Output
Set #1The minimum number of moves is 5.水题注意看题最小没有坑点#include <stdio.h>#include <string.h>int main(){int n, num[55], count = 1, sum, sum2;while (scanf("%d", &n) != EOF) {if (n == 0)break;memset(num, 0, sizeof(num));for (int i = 0; i < n; i++)scanf("%d", &num[i]);sum = 0;for (int i = 0; i < n; i++)sum += num[i];sum = sum / n;sum2 = 0;for (int i = 0; i < n ; i++)if (num[i] > sum)sum2 += num[i] - sum;printf("Set #%d\n", count++);printf("The minimum number of moves is %d.\n\n", sum2);}return 0;}
- 数学D - Box of Bricks
- UVA 591 (暑假-数学 -D - Box of Bricks)
- UVA 591 - Box of Bricks(数学)
- Box of Bricks
- 1477 Box of Bricks
- 1477:Box of Bricks
- 1477 Box of Bricks
- 591 - Box of Bricks
- HDOJ1326 Box of Bricks
- HDU1326:Box of Bricks
- 591 - Box of Bricks
- 591 - Box of Bricks
- UVA591- Box of Bricks
- BNU Box of Bricks
- Box of Bricks
- hdu1326 Box of Bricks
- Box of Bricks
- Box of Bricks
- HDOJ Robberies(好题背包)
- MSHFlexgrid和MSflexgrid控件异同
- Codeforces 570A__Elections
- 用递归算法求n阶勒让得多项式的值
- UIAlertView的基本用法
- 数学D - Box of Bricks
- windows查看端口占用情况
- Thinkphp常用配置文件
- javascript知识回顾
- 树结构练习——判断给定森林中有多少棵树
- Python各进制间的转换
- android DialogFragment
- java成长之路 JVM内存组成及分配
- 推荐大学生看的一些书