题意:给出一堆高度不一的砖头,现在使他们高度一样,问最少的移动次数,(每减少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. No.5 Verilog 建模方式

    5-1 门级建模 VerilogHDL内建基元门: 多输入门:and, nand, or, nor, xor, xnor; 多输出门:buf, not 三态门:bufif0, bufif1, noti ...

  2. JS 鼠标键盘HTML事件

  3. Python之其他数据类型

    1.可命名元组:namedtuple 由nametuple可创建一个包含tuple所有功能以及其他功能的类型 class Mytuple(__builtin__.tuple) | Mytuple(x, ...

  4. qt获取本机用户名

    //获取用户名 QString getUserName() { #if 1 QStringList envVariables; envVariables << "USERNAME ...

  5. LintCode刷题笔记-- Count1 binary

    标签: 位运算 描述: Count how many 1 in binary representation of a 32-bit integer. 解题思路: 统计一个int型的数的二进制表现形式中 ...

  6. 模拟登录新浪微博(Python) - 转

    Update: 如果只是写个小爬虫,访问需要登录的页面,采用填入cookie 的方法吧,简单粗暴有效,详细见:http://www.douban.com/note/264976536/模拟登陆有时需要 ...

  7. 详解composer的自动加载机制

    composer是一个用PHP开发的用来管理项目依赖的工具,当你在项目中声明了依赖关系后,composer可以自动帮你下载和安装这些依赖库,并实现自动加载代码. 安装composer composer ...

  8. VS2008中为控件添加属性(比如前景色,背景色)

    VS2008中没有classwizard,但不要伤心,到了VS2010,classwizard又回来了. 可以参照这篇博客:http://blog.csdn.net/candyliuxj/articl ...

  9. day25 CMDB(1)

    CMDB项目介绍 参考地址: http://www.cnblogs.com/wupeiqi/articles/4556300.html http://www.cnblogs.com/wupeiqi/a ...

  10. TIJ——Chapter Fourteen:Type Information

    Runtime type information(RTTI) allows you to discover and use type information while a program is ru ...