c_cpp uva591

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp uva591相关的知识,希望对你有一定的参考价值。

#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

size_t min_moves(const vector<size_t> &stacks)
{
    auto average = accumulate(stacks.begin(), stacks.end(), 0) / stacks.size();

    return accumulate(stacks.begin(), stacks.end(), 0, [average](size_t init, size_t value)
    {
        return init + (value > average ? value - average : 0);
    });
}

bool test_case(size_t case_num)
{
    size_t n;
    cin >> n;

    if (n == 0) return false;

    vector<size_t> stacks(n);
    for (auto &s : stacks) cin >> s;

    cout << "Set #" << case_num << endl;
    cout << "The minimum number of moves is " << min_moves(stacks) << "." << endl;
    cout << endl;

    return true;
}

int main()
{
    size_t num = 1;
    while (test_case(num++));
    return 0;
}

以上是关于c_cpp uva591的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp uva10093

c_cpp uva12307

c_cpp uva681

c_cpp uva10101

c_cpp uva10107

c_cpp uva12015