描述

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?

输入

The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1 <= n <= 50 and 1 <= hi <= 100.
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.

输出

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.

样例输入

6
5 2 4 1 7 5
0

样例输出

Set #1
The minimum number of moves is 5.
#include<stdio.h>
int main(void)
{
int n, sum, ans, average, count = ;
int a[]; while(scanf("%d", &n) && n)
{
sum = ans = ;
for(int i = ; i <= n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
}
average = sum / n;
for(int i = ; i <= n; i++)
{
if(a[i] < average)
ans = ans + average - a[i];
}
printf("Set #%d\nThe minimum number of moves is %d.\n\n", count++, ans);
} return ;
}

OpenJudge_1477:Box of Bricks的更多相关文章

  1. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. Box of Bricks最小移动砖块数目

    Description Little Bob likes playing with his box of bricks. He puts the bricks one upon another and ...

  3. [POJ1477]Box of Bricks

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19503   Accepted: 7871 Description Litt ...

  4. HDOJ(HDU) 2088 Box of Bricks(平均值)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  5. HDOJ 1326 Box of Bricks(简单题)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  6. 591 - Box of Bricks

     Box of Bricks  Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...

  7. Box of Bricks

    Box of Bricks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  8. HDU 2088 Box of Bricks

    http://acm.hdu.edu.cn/showproblem.php?pid=2088 Problem Description Little Bob likes playing with his ...

  9. HDU 2088 Box of Bricks(脑洞)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Oth ...

随机推荐

  1. struts2-环境搭建-访问流程-配置详解-常量配置-类详解

    1 struts2概述 1.1 概念  1.2 struts2使用优势 自动封装参数 参数校验 结果的处理(转发|重定向) 国际化 显示等待页面 表单的防止重复提交 struts2具有更加先进的架构以 ...

  2. numpy使用中的疑惑

    numpy中有一些常用的用来产生随机数的函数,randn就是其中一个,randn函数位于numpy.random中,函数原型如下: numpy.random.randn(d0, d1, ..., dn ...

  3. Ubuntu18.04 + win10双系统下时间问题

    Ubuntu 16.04使用systemd启动之后,时间也改成了由timedatectl来管理 解决的办法可以参考http://blog.sina.com.cn/s/blog_5379c55b0102 ...

  4. Django项目:CRM(客户关系管理系统)--30--22PerfectCRM实现King_admin数据添加

    登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html # king_urls.py # ————————02PerfectCRM创建ADMIN页面—— ...

  5. php mkdir 777失败

    参考网址:https://www.cnblogs.com/52php/p/5660079.html 在linux系统中在创建文件/文件夹时有一个默认权限,此权限受 umask 设置影响,在/etc/b ...

  6. springmvc java程序文件保存地址的路径问题

    会保存为这种斜杠 不论之前填写的是什么样

  7. Boost Asio教程集合

    http://zh.highscore.de/cpp/boost/ 第七章 https://mmoaay.gitbooks.io/boost-asio-cpp-network-programming- ...

  8. MySQL忘记root密码重置密码(5.7版本)

    网上找了一堆方法都不行,经过折腾一番,发现MySQL不同版本重置密码也存在一定的差异!记录下Mysql5.7.18版本的重置密码方法. 1.找到/etc/mysql/my.cnf 修改此文件添加一行s ...

  9. DNS客户端配置文件/etc/resolv.conf

    本来不应该把DNS客户端配置文件放在这里来说,但由于新手弟兄上网时,虽然能拔号,但不能以域名访问.究其原因是由于没有修改 /etc/resolv.conf 文件: /etc/resolv.conf 里 ...

  10. linux之bc命令

    当在脚本中要处理浮点数计算时,就可以使用bc计算器,先看下面的例子 [root@node2 tmp]# cat bc.sh #!/bin/bash # num1=`echo "scale=3 ...