hdu ACM Steps 1.2.4 Box of Bricks

模拟题。

题意为把高度不同的砖头堆变成高度相同的砖头堆最少需要移动几次。

想想就知道,要把每个砖头堆变成平均高度砖头堆最少需要移动的块数就是俩者的差值。

把所有差值都加起来以后要除以2,因为移动一块砖头对俩个砖头堆有影响。

#include<cstdio>
#include<cmath>
const int maxn = 100 + 10;

int a[maxn],n,s,h,ans,kase;

int main() {
    while(scanf("%d",&n) && n) {
        s=ans=0;
        for(int i=1;i<=n;i++) {
            scanf("%d",&a[i]);
            s+=a[i];
        }
        h=s/n;
        for(int i=1;i<=n;i++) ans+=abs(h-a[i]);
        ans/=2;
        printf("Set #%d\nThe minimum number of moves is %d.\n",++kase,ans);
        printf("\n");
    }
    return 0;
}

时间: 2024-10-18 10:17:53

hdu ACM Steps 1.2.4 Box of Bricks的相关文章

hdu ACM Steps 1.2.8 Balloon Comes!

水题 #include<cstdio> char s[10]; int T,a,b,res; int main() { scanf("%d",&T); while(T--) { scanf("%s%d%d",s,&a,&b); switch (s[0]) { case '+' : printf("%d\n",a+b); break; case '-' : printf("%d\n",a-b)

hdu ACM Steps 1.3.1 第二小整数

水题. 我还以为是快速选择,但快排直接就过了. #include<cstdio> #include<algorithm> using namespace std; const int maxn = 500000 + 10; int a[maxn]; int T,n; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=1;i<=n;i++

hdu ACM Steps 1.2.5 find your present (2)

基础题.异或. 这道题很简单.但一开始我并没有想到O(n)的算法,然后排序tle了一发. 后来一直在想怎么使得俩个相同数互相"抵消"掉,灵机一动,发现这是异或. #include<cstdio> #include<algorithm> using namespace std; const int maxn = 100000 + 10; int a,n,ans; int main() { while(scanf("%d",&n) &am

hdu ACM Steps 1.2.3 A+B Coming

模拟题. 16进制转化为10进制相加.toupper函数为小写转换为大写,isalpha函数判断是否为字母. #include<cstdio> #include<cstring> #include<cctype> using namespace std; const int maxn = 100 + 10; const int base = 16; char s[5][maxn]; int a,b; int trans(int m) { int ans=0,n=strl

杭电 HDU ACM 1326 Box of Bricks

Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5457    Accepted Submission(s): 2358 Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one up

HDU 1326 Box of Bricks(简单数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 Problem Description 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 siste

HDU 2088 Box of Bricks(脑洞)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2088 Box of Bricks Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 20219    Accepted Submission(s): 6473 Problem Description Little Bob likes playi

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且