【HDU - 1326】Box of Bricks(模拟水题)

题干:

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? 


InputThe 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. 
OutputFor 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.


解题报告:

    水题不解释。

ac代码:

#include <bits/stdc++.h>using namespace std;
int a[100 + 5];
int sum;
int ans;
int main()
{int n;int iCase=0;while(~scanf("%d",&n) && n ) {ans=sum=0;for(int i = 0; i<n; i++) {scanf("%d",&a[i]);sum+=a[i];	}for(int i = 0; i<n; i++) {if(a[i]>sum/n) {ans+=a[i]-sum/n;	}}printf("Set #%d\n",++iCase);printf("The minimum number of moves is %d.\n\n",ans);}return 0 ;
}


总结:

    无


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/442106.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

微信公众平台网站开发JS_SDK遇到的bug——wx.config注册提示成功,但部分接口注册失败问题

1 2022-02-23 使用微信公众平台调用扫一扫接口&#xff0c;总是注册不成功 这是进行注册后成功注册的接口提示 尝试注册了以下接口 拥有相关权限 解决办法&#xff1a;猜测失败原因为&#xff1a;子界面进行注册&#xff0c;在父界面进行注册后&#xff0c;成功

layui 流加载flow遇到的问题

目的&#xff1a;在界面中想实现&#xff0c;进入界面加载部分数据&#xff0c;拥有搜索功能&#xff0c;可加载新的数据以替换旧数据&#xff0c;替换过程中想要清空现有数据时&#xff0c;使用jquery方法 $(*).remove();删除了流控件&#xff0c;特别记录一下问题&#xff0…

【HDU - 1276】士兵队列训练问题 (报数问题 模拟)

题干&#xff1a;某部队进行新兵队列训练&#xff0c;将新兵从一开始按顺序依次编号&#xff0c;并排成一行横队&#xff0c;训练的规则如下&#xff1a;从头开始一至二报数&#xff0c;凡报到二的出列&#xff0c;剩下的向小序号方向靠拢&#xff0c;再从头开始进行一至三报数…

React学习,Babel ES6兼容运行使用的命令行整理

测试项目为&#xff0c;一个js文件引用其他ES6编写的文件&#xff0c;最终网页中引用打包好的最终js文件 注意&#xff1a;需要安装Node.js,没有的话&#xff0c;需要搜索安装 1 Browserify //在终端中输入如下命令&#xff0c;可以通过 npm 安装 Browserify&#xff1a; $ n…

【HDU - 1870】愚人节的礼物(水题模拟 思想类似于栈?)

题干&#xff1a;四月一日快到了&#xff0c;Vayko想了个愚人的好办法——送礼物。嘿嘿&#xff0c;不要想的太好&#xff0c;这礼物可没那么简单&#xff0c;Vayko为了愚人&#xff0c;准备了一堆盒子&#xff0c;其中有一个盒子里面装了礼物。盒子里面可以再放零个或者多个盒…

c++经典编程题_【经典C语言知识】C/C++编程难点总结

知识点一&#xff1a;指针1. 指针&#xff1a;变量在内存中所存储空间的首编号&#xff0c;就称作为该变量的地址&#xff0c;也叫做指针。指针变量: 他专门存放另外一个变量的指针 int* p_age&#xff1b;p_age&age;2.数组与指针使用指针访问一维数组元素&#xf…

asp.net mvc 缓存CaChe使用

缓存存储帮助类 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Caching;public class TCatche{/// <summary> /// 获取数据缓存 /// </summary> /// <param name"cacheKey">键<…

【CF#459 A 】Pashmak and Garden (水题)

题干:Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden l…

c++ 低位在前 高位在后_A股市场:如果股票涨停后第二天“高开低走”,你知道怎么操作才能利益最大化吗?...

(本文由公众号越声策略(yslc188)整理&#xff0c;仅供参考&#xff0c;不构成操作建议。如自行操作&#xff0c;注意仓位控制和风险自负。)如果你的股票涨停后第二天高开低走&#xff0c; 后市怎么操作&#xff1f;简单来讲&#xff0c;高开低走就是开盘价高于上个交易日的收盘…

2018年工业机器人销量排位_工业机器人年销量连续七年居世界首位 专家建议开辟新市场...

12月17日&#xff0c;粤港澳大湾区人工智能与机器人大会在广东四会举行。本次大会的主题是“智慧湾区&#xff0c;引领未来”。大会邀请了国际机器人联合会、粤港澳大湾区相关专家、国内外学者和企业专家深度交流&#xff0c;共话机器人发展的新风向。中国机械工业联合会执行副…

*【HDU - 2473】Junk-Mail Filter (并查集--删点操作)

题干&#xff1a; Recognizing junk mails is a tough task. The method used here consists of two steps: 1) Extract the common characteristics from the incoming email. 2) Use a filter matching the set of common characteristics extracted to determine whether…

文件内容查找方式

第一种&#xff0c;使用windows自带的查找工具 搜索工具里面有”高级选项“&#xff0c;选择”文件内容“然后进行搜索即可 第二种&#xff0c;使用命令行 在需要进行搜索的文件夹下使用命令行&#xff1a; Get-ChildItem -Path F:\ -Recurse | Select-String -Pattern &qu…

【HDU - 1863】 畅通工程(并查集+最小生成树)

题干&#xff1a; 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通&#xff08;但不一定有直接的公路相连&#xff0c;只要能间接通过公路可达即可&#xff09;。经过调查评估&#xff0c;得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编…

C# 删除文件夹下的文件

/// <summary>/// 删除某个时间之前的所有文件/// </summary>/// <param name"aUrl"></param>/// <param name"aTime"></param>public static void RemoveFile(string aUrl,DateTime aTime) {var bFiles Directory.G…

【POJ - 1287】 Networking (并查集 + 最小生成树)

题干&#xff1a; You are assigned to design network connections between certain points in a wide area. You are given a set of points in the area, and a set of possible routes for the cables that may connect pairs of points. For each possible route between…

C# 程序xml文件生成和读写操作

public class XmlFile{private string fileFolder;private string fileName;private string fPathBase Directory.GetCurrentDirectory(); //结尾没有反斜杠public TimeConfig(string aFileFolder "xmlConfig", string aFileName "config"){fileFolder…

【HDU - 1301】Jungle Roads(并查集+最小生成树)(内附最小生成树两种算法 克鲁斯特尔算法amp;amp;普里姆算法)

题干&#xff1a; Jungle Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5505 Accepted Submission(s): 3976 Problem Description The Head Elder of the tropical island of Lagrishan has a proble…

vscode中怎样格式化js代码_[VSCode插件推荐] Bracket Pair Colorizer: 为代码中的括号添上一抹亮色...

在代码编写过程中&#xff0c;各种括号 {[()]} 必不可少。然而&#xff0c;随着代码量的增加&#xff0c;你有没有因为括号的嵌套太多&#xff0c;而导致代码难以阅读&#xff1f;我们来看看下面的代码&#xff0c;在第三行代码的最后部分&#xff0c;连续出现了5个右括号&…

Asp.net MVC 从ftp服务器读取文件保存到网站本地

1 FTP连接辅助类 /// <summary>/// FTP操作单元/// </summary>public class TFTPOperationUnit{/// <summary>/// ftp地址/// </summary>private string FFTPUrl;/// <summary>/// ftp用户名/// </summary>string FFTPUserName;/// <s…

多帧点云数据拼接合并_自动驾驶:Lidar 3D传感器点云数据和2D图像数据的融合标注...

自动驾驶汽车的发展已经见证了硬件传感器记录感官数据的容量和准确度的发展。传感器的数量增加了&#xff0c;新一代传感器正在记录更高的分辨率和更准确的测量结果。 在本文中&#xff0c;我们将探讨传感器融合如何在涉及环环相扣的数据标记过程中实现更高程度的自动化。所有自…