1014 Waiting in Line --队列模拟

来源:互联网 发布:网络销售好做吗做金融 编辑:程序博客网 时间:2024/05/21 06:24

模拟题,注意题意。。。

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