Pat 1017. Queueing at Bank (25)

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.