PAT(甲) - 1014 Waiting in Line

#include <bits/stdc++.h>
using namespace std;

typedef struct
{
    int start;
    int length;
    int end;
} cu;

string t2s(int t)
{
    int h = 8 + t / 60;
    int m = t % 60;
    string temp = "";
    if (h < 10)
        temp = temp + "0";
    temp = temp + to_string(h) + ":";
    if (m < 10)
        temp = temp + "0";
    temp = temp + to_string(m);
    return temp;
}

int main()
{
    ios::sync_with_stdio(false);
    int n, m, count, q;
    cin >> n >> m >> count >> q;
    cu customer[count + 1];
    for (int i = 1; i <= count; i++)
    {
        cin >> customer[i].length;
    }

    queue<cu *> qu[n];
    int time = 0;
    for (int i = 1; i <= count; i++)
    {
        int man = 1;
        int pos;
        int minn = 65535;
        for (int j = 0; j < n; j++)
        {
            if (qu[j].size() < m)
            {
                man = 0;
                if (qu[j].size() < minn)
                {
                    minn = qu[j].size();
                    pos = j;
                }
            }
        }
        if (!man)
        {
            if (qu[pos].empty())
            {
                customer[i].start = time;
                customer[i].end = time + customer[i].length;
                qu[pos].push(&customer[i]);
            }
            else
            {
                customer[i].start = qu[pos].back()->end;
                customer[i].end = customer[i].start + customer[i].length;
                qu[pos].push(&customer[i]);
            }
        }
        else
        {
            for (int j = 0; j < n; j++)
            {
                if (qu[j].front()->end < minn)
                {
                    minn = qu[j].front()->end;
                    pos = j;
                }
            }
            time = minn;
            customer[i].start = qu[pos].back()->end;
            customer[i].end = customer[i].start + customer[i].length;
            qu[pos].pop();
            qu[pos].push(&customer[i]);
        }
    }
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if (customer[t].start >= 540)
            cout << "Sorry" << endl;
        else
            cout << t2s(customer[t].end) << endl;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值