若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1625: Box of Bricks

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,095

题目描述

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?

输入

暂无

输出

暂无

样例输入

6
5 2 4 1 7 5
0

样例输出

Set #1
The minimum number of moves is 5.

参考代码

#include<stdio.h>
int s[100];
int main() 
{
    int i,j,n,sum,k,l=1;
    while(scanf("%d",&n) && n) 
    {
        sum=0;
        k=0;
        for (i=0;i<n;i++) 
        {
            scanf("%d",&s[i]);
            sum+=s[i];
        }
        j=sum/n;
        for (i=0;i<n;i++) 
        {
            if(s[i]>j)
                        k+=s[i]-j;
        }
        printf("Set #%dnThe minimum number of moves is %d.nn",l,k);
        l++;
    }
    return 0;
}

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

Dreams孤独患者 原站点 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist