其他分享
首页 > 其他分享> > 排队等候

排队等候

作者:互联网

https://www.acwing.com/problem/content/description/1488/

思路:
依然核心问题是:搞经常模拟的是什么东西,如果这题模拟时间,会很烦,但模拟队列的情况,会简单很多。

#include <iostream>
#include <cstring>
#include <queue>
#include <unordered_map>

using namespace std;

const int N = 20;

int n, m, k, Q;
int sum[N];
queue<int> q[N];

int main()
{
    cin >> n >> m >> k >> Q;

    unordered_map<int, int> hash;
    for (int i = 1; i <= k; i ++ )
    {
        int s;
        cin >> s;

        int t = 0;
        for (int j = 0; j < n; j ++ )
            if (i <= n * m)
            {
                if (q[j].size() < q[t].size()) t = j;
            }
            else
            {
                if (q[j].front() < q[t].front()) t = j;
            }

        sum[t] += s;
        if (i > n * m) q[t].pop();
        q[t].push(sum[t]);

        if (sum[t] - s < 540) hash[i] = sum[t];
    }

    while (Q -- )
    {
        int id;
        cin >> id;
        if (hash.count(id)) printf("%02d:%02d\n", hash[id] / 60 + 8, hash[id] % 60);
        else puts("Sorry");
    }

    return 0;
}

标签:等候,02d,hash,int,sum,排队,include,id
来源: https://www.cnblogs.com/xjtfate/p/16615718.html