PAT Class 1014 Waiting in Line (30) queue + (problem error code attached)

Keywords: Windows REST

Title:

Banks have n windows, each window can have up to m people queuing; (!!! Note: These people do not choose windows by themselves in order, they can only choose windows in order from 1-n rows.

If n windows are full, the rest of the people will stand behind the yellow line and wait until there is a discontented window queue before queuing one by one. In the past, when queuing, the number of queues is small, if the number of queues is the same, the number of windows with small labels will be chosen first.

Train of thought:

The queue of a window is represented by a queue, which contains the end time of each person.

a [] denotes each person's business time, b [] denotes the end of each person's business, and c [] denotes the current time at which all people in each window complete their business.

First put the front n*m people (if enough) in the queue; the remaining people outside the Yellow line, one by one, into the queue.

 

(At the beginning, the error code assumed that each of the first n*m members entered the team according to the best criteria: the error is as follows: https://blog.csdn.net/xiang_6/article/details/100135748)

#include<bits/stdc++.h>
#include<cstring>
#define FI first
#define SE second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1000 + 7;
const int maxd = 100 + 7;
const int INF = 0x7f7f7f7f;

int n, m, k, q;
int a[maxn], b[maxn]; // Office hours and end times for each customer

int c[maxd]; // Latest idle time of each window
queue<int> qu[maxd]; // Window queue (end time)


int getid2() {
    int res, min_ = INF;
    for(int i = 1; i <= n; ++i) {
        if(qu[i].size() == 0) continue;
        if(qu[i].front() < min_) {
            min_ = qu[i].front();
            res = i;
        }
    }
    return res;
}
void init() {
    int M = n*m, pos = 1;
    for(int i = 1; i <= m; ++i) {
        for(int j = 1; j <= n; ++j) {
            if(pos <= k) {
                c[j] += a[pos];
                b[pos] = c[j];
                qu[j].push(c[j]);
            }
            pos++;
        }
    }
    for(int i = M+1; i <= k; ++i) {
        int id = getid2();
        c[id] += a[i];
        b[i] = c[id];
        qu[id].push(c[id]);
        qu[id].pop();
    }
}
int main() {
    scanf("%d%d%d%d", &n, &m, &k, &q);
    for(int i = 1; i <= k; ++i) {
        scanf("%d", &a[i]);
    }
    init();
    int t;
    for(int i = 1; i <= q; ++i) {
        scanf("%d", &t);
        if(b[t]-a[t] < 540) {
            printf("%02d:%02d\n", (8+b[t]/60), (b[t]%60));
        }
        else {
            puts("Sorry");
        }
    }
    return 0;
}

 

Posted by hermzz on Thu, 03 Oct 2019 10:56:15 -0700