yuanfudao

作者: Songger | 来源:发表于2019-08-24 16:00 被阅读0次

diyiti:

#include <iostream>
#include <vector>

using namespace::std;

int main()
{
    int groupsNum = 0;
    cin >> groupsNum;

    vector<int> res;
    for (size_t i = 0; i < groupsNum; i++)
    {
        int count = 0;
        cin >> count;
        vector<int> group = {};
        for (size_t j = 0; j < count; j++)
        {
            int n = 0;
            cin >> n;
            group.push_back(n);
        }
        
        vector<int> tmp;
        for(auto e : group)
        {
            if(e != 0) tmp.push_back(e);
        }
        group = tmp;

        int aws = 0;
        while (group.size() > 2)
        {
            tmp.clear();
            aws++;
            for(auto &e : group)
            {
                e--;
                if (e != 0) 
                {
                    tmp.push_back(e);
                }
            }
            group = tmp;
            res.push_back(aws);
        }
        
    }

    for (size_t i = 0; i < res.size(); i++)
    {
        cout << res[i] << endl;
    }
    
    return 0;
}

相关文章

网友评论

      本文标题:yuanfudao

      本文链接:https://www.haomeiwen.com/subject/qnrqectx.html