1014 Waiting in Line --队列模拟

模拟题,注意题意。。。

for those customers who cannot be served before 17:00, you must output “Sorry” instead.

17点之前被接待了,服务超过17点也不要紧。

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

struct node {
    int id, time;
    node(int i, int t):id(i), time(t) {}
    friend bool operator<(const node &a, const node &b) {
        a.time < b.time;
    }
};

queue<node> que[25];
int wdt[25];
int cus[1010], ans[1010];

void print(int x) {
    if (!x) {
        printf("Sorry\n");
        return;
    }
    int h = x / 60 + 8;
    int m = x % 60;
    printf("%02d:%02d\n", h, m);
}

int main() {
    int n, m, k, q;
    scanf("%d%d%d%d", &n, &m, &k, &q);
    for (int i = 1; i <= k; i++)
        scanf("%d", cus+i);

    int ptr = 1, inque = 0;
    memset(wdt, 0, sizeof(wdt));
    do {
        while (ptr <= k && inque < n*m) {
            int mi = 1;
            for (int i = 2; i <= n; i++)
                if (que[i].size() < que[mi].size())
                    mi = i;
            que[mi].push(node(ptr, wdt[mi] + cus[ptr]));
            if (wdt[mi] < 540)
                ans[ptr] = wdt[mi] + cus[ptr];
            else
                ans[ptr] = 0;
            wdt[mi] += cus[ptr];
            inque++;
            ptr++;
        }
        int ti;
        bool first = true;
        for (int i = 1; i <= n; i++) {
            if (first && !que[i].empty()) {
                ti = i;
                first = false;
            }else if (!first && que[i].front().time < que[ti].front().time)
                ti = i;
        }
        node t = que[ti].front();
        que[ti].pop();
        inque--;
    } while (inque);

    while (q--) {
        int x;
        scanf("%d", &x);
        print(ans[x]);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值