题意:给出一堆高度不一的砖头,现在使他们高度一样,问最少的移动次数,(每减少1就是移动一次)

思路:求出平均高度,然后模拟最后平均高度的数组,也就是说,每个数组对应每一个平均高度,也就是说比平均高度大的那些数据,就移动了,就这样直接求和

 #include<iostream>
#include<algorithm>
using namespace std;
int num[];
int main()
{
int n,t=;
while(cin >> n &&n)
{
int tot=;
for(int i=;i<n;++i){
cin >> num[i];
tot+=num[i];
}
int ave=tot/n;
int tar[];
fill(tar,tar+n,ave);
int sn=tot%n;
for(int i=n-;i>=&&sn;--i){
num[i++];sn--;
}
int mmin=;
for(int i=;i<n;++i)
if(tar[i]<num[i]) mmin+=num[i]-tar[i];
cout << "Set #" << t++ << endl;
cout << "The minimum number of moves is " << mmin << "." << endl;
cout << endl;
}
}

HDU 1326的更多相关文章

  1. HDU 1326 Box of Bricks(水~平均高度求最少移动砖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...

  2. HDU 1326 Box of Bricks(思维)

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

  3. HDOJ 1326. Box of Bricks 纯水题

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

  4. HDU——PKU题目分类

    HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 ...

  5. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  6. HDU ACM 题目分类

    模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 104 ...

  7. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. xml-apis.jar getTextContent() jar包冲突解决(getTextContent()方法无法找到)

    1.引用包: import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList; 2.方法中应用: ...

  2. python 模块 chardet下载及介绍

    python 模块 chardet下载及介绍   在处理字符串时,常常会遇到不知道字符串是何种编码,如果不知道字符串的编码就不能将字符串转换成需要的编码.面对多种不同编码的输入方式,是否会有一种有效的 ...

  3. HTTP请求封装Java工具类

    装载自:http://www.open-open.com/lib/view/open1384844838743.html package com.wiker; import java.io.Buffe ...

  4. 使用mpvue开发github小程序总结

    前言 最近有点闲,想起关注已久的mpvue写小程序,所以稍微肝了半个多月写了个github版的微信小程序,已上线.现在总结一下遇到的坑. 扫码体验. 项目地址.https://github.com/c ...

  5. C++通配符

    #include<iostream>using namespace std;bool PathernMatch(char *pat, char *str){ char *s = NULL; ...

  6. POJ1485 Sumdiv

    Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22680   Accepted: 5660 Descripti ...

  7. 【水滴石穿】imooc_gp

    这个项目应该是一个标杆项目,看到之前很有几个项目都是按照这个项目的页面摆放顺序来的 不过可以作为自己做项目的一种方式 源码地址为:https://github.com/pgg-pgg/imooc_gp ...

  8. svn upgrade

    在我们把我们服务器上的svn 版本号升级以后,我们之前的代码再执行svn命令时,会提示需要执行svn upgrade命令把当前的代码由低版本的svn 上迁移到高版本的svn 上去. 直接执行svn u ...

  9. fusion-io工具--更换fusion-ioSSD无法识别及升级指引

    centos6.5系统,(含fusion-io共7块盘)库存的fusion-io卡需要升级固件才能识别 现在只认到6个盘 fdisk -l 2>/dev/null | grep 'Disk /d ...

  10. 在Struts2里面嵌入Spring

    第一步:在web.xml中增加以下的listener <listener> <listener-class>org.springframework.web.context.Co ...