1017 Queueing at Bank (25 分)
Suppose a bank has K windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.
Now given the arriving time T and the processing time P of each customer, you are supposed to tell the average waiting time of all the customers.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤104) - the total number of customers, and K (≤100) - the number of windows. Then N lines follow, each contains 2 times: HH:MM:SS
- the arriving time, and P - the processing time in minutes of a customer. Here HH
is in the range [00, 23], MM
and SS
are both in [00, 59]. It is assumed that no two customers arrives at the same time.
Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.
Output Specification:
For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.
Sample Input:
1 | 7 3 |
Sample Output:
1 | 8.2 |
作者: CHEN, Yue
单位: 浙江大学
时间限制: 400 ms
内存限制: 64 MB
代码长度限制: 16 KB
题目大意
一家银行有k个窗口,与1014不同的是黄线内只能站一人。单个的顾客不能占用窗口超过一小时,给出窗口数,顾客到达时间以及处理时间,求所有用户的平均等待时间。银行早上8点开门,提早到的顾客必须等待,晚于17点到的顾客不会被服务,也不计入计算。
分析
利用一个window数组纪录窗口可以开始服务的时间,初始化为8点。顾客进入时加上相应的处理时间即可。利用map<int,int>
纪录顾客的到达时间以及处理时间,每次选择最早开始服务的窗口,服务最早来的顾客即可。
代码
1 |
|