Queue simulation question Note: The question is calculated as the average waiting time. If the customer arrives before, it must wait until. If the customer arrives after, banks do not provide services for them, but once the arrival time is before, even if the end time is after, banks must also serve [cpp] # include <iostream> # include <queue> # include <vector> # include <algorithm> # include <stdio. h> # include <string. h> using namespace std; # define S 8*60*60 # define E 17*60*60 # define INF 0x7fffffff struct node {int time; int process; int begin; int leave;}; int max (int a, int B) {return a> B? A: B;} int cmp (struct node a, struct node B) {return. time <B. time;} int main () {int n, k, I, h, m, s, j, min, index, t; while (scanf ("% d ", & n, & k )! = EOF) {vector <struct node> cus (n); // vector <queue <int> winque (k); vector <int> now (k, S ); for (I = 0; I <n; I ++) {scanf ("% d: % d", & h, & m, & s, & cus [I]. process); cus [I]. process * = 60; cus [I]. time = (h * 60 + m) * 60 + s;} sort (cuz. begin (), cuz. end (), cmp); for (I = 0; I <n; I ++) {min = INF; for (j = 0; j <k; j ++) if (min> now [j]) {min = now [j]; index = j;} cus [I]. begin = max (now [index], cus [I]. time); cus [I]. leave = cuz [I]. begin + cuz [I]. process; now [index] = cus [I]. leave;} t = 0; s = n; for (I = 0; I <n; I ++) {// printf ("% d \ n", I, cus [I]. time, cus [I]. begin, cuz [I]. leave); if (cus [I]. time <= E) // Anyone arrives early will have to wait in line till 17:00:01, // and anyone comes too late (at or after) will not be served nor counted into the average. // anyone who arrives at the bank before will serve it {t + = cuz [I]. begin-Cuz [I]. time; // printf ("% d \ n", t);} else s --;} if (s) printf ("%. 1lf \ n ", t/60.0/s); // calculate the average wait time else printf (" 0.0 \ n ");} return 0 ;}