TOJ 1601

简介: 1601.   Box of BricksTime Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 5007   Accepted Runs: 1950 Little Bob likes playing with his box of bricks.
1601.   Box of Bricks
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 5007    Accepted Runs: 1950



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 consideration, 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 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.


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

6
5 2 4 1 7 5
0


Sample Output

Set #1
The minimum number of moves is 5.
//大于平均值的部分加和 ,简单题目,学习vector 
//AC
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int i,j,k,T;
    int flag = 1;//必须开在while外,并且初始化0 
    while(cin>>T,T)
    {
        int sum = 0;
        vector <int > v;
        for(i=1;i<=T;i++)
        {
            int temp;
            cin>>temp;
            v.push_back(temp);
            sum += temp;
        }
        int aver = sum / v.size();
        int ans = 0;
        for(i=0;i<v.size();i++)
            if(v.at(i)>aver)
                ans += v.at(i) - aver;
        //if(flag>1)
            
        cout<<"Set #"<<flag<<endl;
        cout<<"The minimum number of moves is "<<ans<<"."<<endl;
        cout<<endl;
        flag++;
        v.clear();
    }
    //system("pause");
    return 0;
}
 
 
 //个人认为,应该
 #include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int i,j,k,T;
    int flag = 1;//必须开在while外,并且初始化0 
    while(cin>>T,T)
    {
        int sum = 0;
        vector <int > v;
        for(i=1;i<=T;i++)
        {
            int temp;
            cin>>temp;
            v.push_back(temp);
            sum += temp;
        }
        int aver = sum / v.size();
        int ans = 0;
        for(i=0;i<v.size();i++)
            if(v.at(i)>aver)
                ans += v.at(i) - aver;
        if(flag>1)
            cout<<endl;  
        cout<<"Set #"<<flag<<endl;
        cout<<"The minimum number of moves is "<<ans<<"."<<endl;
        flag++;
        v.clear();
    }
    //system("pause");
    return 0;
}
            
            
        

 

目录
相关文章
|
6天前
|
NoSQL Cloud Native Redis
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
阿里云瑶池数据库团队后续将持续参与Valkey社区,如过往在Redis社区一样耕耘,为开源社区作出持续贡献。
Redis核心开发者的新征程:阿里云与Valkey社区的技术融合与创新
|
6天前
|
关系型数据库 分布式数据库 数据库
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
PolarDB分布式版助力《香肠派对》实现百亿好友关系20万QPS的毫秒级查询。
PolarDB闪电助攻,《香肠派对》百亿好友关系实现毫秒级查询
|
7天前
|
消息中间件 Cloud Native Serverless
RocketMQ 事件驱动:云时代的事件驱动有啥不同?
本文深入探讨了云时代 EDA 的新内涵及它在云时代再次流行的主要驱动力,包括技术驱动力和商业驱动力,随后重点介绍了 RocketMQ 5.0 推出的子产品 EventBridge,并通过几个云时代事件驱动的典型案例,进一步叙述了云时代事件驱动的常见场景和最佳实践。
115050 1
|
8天前
|
弹性计算 安全 API
访问控制(RAM)|云上安全使用AccessKey的最佳实践
集中管控AK/SK的生命周期,可以极大降低AK/SK管理和使用成本,同时通过加密和轮转的方式,保证AK/SK的安全使用,本次分享为您介绍产品原理,以及具体的使用步骤。
101814 1
|
7天前
|
自然语言处理 Cloud Native Serverless
通义灵码牵手阿里云函数计算 FC ,打造智能编码新体验
近日,通义灵码正式进驻函数计算 FC WebIDE,让使用函数计算产品的开发者在其熟悉的云端集成开发环境中,无需再次登录即可使用通义灵码的智能编程能力,实现开发效率与代码质量的双重提升。
95390 2
Doodle Jump — 使用Flutter&Flame开发游戏真不错!
用Flutter&Flame开发游戏是一种什么体验?最近网上冲浪的时候,我偶然发现了一个国外的游戏网站,类似于国内的4399。在浏览时,我遇到了一款经典的小游戏:Doodle Jump...
112734 12
|
12天前
|
SQL 存储 JSON
Flink+Paimon+Hologres 构建实时湖仓数据分析
本文整理自阿里云高级专家喻良,在 Flink Forward Asia 2023 主会场的分享。
71322 1
Flink+Paimon+Hologres 构建实时湖仓数据分析
|
16天前
|
弹性计算 运维 安全
访问控制(RAM)|云上程序使用临时凭证的最佳实践
STS临时访问凭证是阿里云提供的一种临时访问权限管理服务,通过STS获取可以自定义时效和访问权限的临时身份凭证,减少长期访问密钥(AccessKey)泄露的风险。本文将为您介绍产品原理,以及具体的使用步骤。
151046 4
|
15天前
|
监控 负载均衡 Java
深入探究Java微服务架构:Spring Cloud概论
**摘要:** 本文深入探讨了Java微服务架构中的Spring Cloud,解释了微服务架构如何解决传统单体架构的局限性,如松耦合、独立部署、可伸缩性和容错性。Spring Cloud作为一个基于Spring Boot的开源框架,提供了服务注册与发现、负载均衡、断路器、配置中心、API网关等组件,简化了微服务的开发、部署和管理。文章详细介绍了Spring Cloud的核心模块,如Eureka、Ribbon、Hystrix、Config、Zuul和Sleuth,并通过一个电商微服务系统的实战案例展示了如何使用Spring Cloud构建微服务应用。
103519 9
|
15天前
|
Java 数据处理 调度
更高效准确的数据库内部任务调度实践,阿里云数据库SelectDB 内核 Apache Doris 内置 Job Scheduler 的实现与应用
Apache Doris 2.1 引入了内置的 Job Scheduler,旨在解决依赖外部调度系统的问题,提供秒级精确的定时任务管理。

热门文章

最新文章