【HDOJ】1326 Box of Bricks

大水题一道,千万别理解复杂。

#include <stdio.h>

#define MAXNUM 50

int main() {
    int heights[MAXNUM], n;
    int i, j, tmp, avg;

    j = 0;
    while (1) {
        scanf("%d", &n);
        if (n == 0)
            break;
        tmp = 0;
        for (i=0; i<n; ++i) {
            scanf("%d", &heights[i]);
            tmp += heights[i];
        }
        avg = tmp / n;
        tmp = 0;
        for (i=0; i<n; ++i) {
            if (heights[i] > avg) {
                tmp += (heights[i]-avg);
            }
        }
        printf("Set #%d\n", ++j);
        printf("The minimum number of moves is %d.\n\n", tmp);
    }

    return 0;
}

 

posted on 2014-03-01 22:23  Bombe  阅读(109)  评论(0编辑  收藏  举报

导航