【模拟】POJ 1477 Box of Bricks

要求一次只能移动一块,只有比average多的柱子上的块需要移动。好水。注意输出a new blank line
#include <cstdio>
#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{
    int n, i, sum, ave, j, ans, t = 1;
    int e[51];
    while(scanf("%d", &n) == 1 && n)
    {
        ave = sum = 0;
        for(i = 1; i <= n; i++)
        {
            scanf("%d", &e[i]);
            sum += e[i];
        }
        ave = sum / n;
        ans = 0;

        for(i = 1; i <= n; i++)
        {
            if(e[i] > ave)
            {
                ans += e[i]-ave;
            }
        }
        cout << "Set #" << t++ << "\nThe minimum number of moves is " << ans << "." << endl << endl;
    }
    return 0;
}


你可能感兴趣的:(【模拟】POJ 1477 Box of Bricks)