Topic Overview
Suppose there are N customers waiting for service in the K window. Each window can hold one person, so other customers need to wait. When a customer service completes, the next customer can enter the window and be serviced. We assume that no window will be occupied for more than 1 hours.
Now we give each customer the arrival time t and the time required to service the customer p, please calculate the average waiting time for all customers.
Input
Each input file contains a test case. For each test case, the first row contains two integers n (<= 1000) and K (<= 100). where n represents the number of customers, K represents the number of Windows.
The next n lines, including two time: HH:MM:SS, indicating the customer's arrival time; P, which indicates the time (in minutes) that is required to service the customer.
The range of HH is [+], and the range of MM and SS is [00, 59]. We assume that no two customers arrive at the same time.
It should be explained that the bank's business hours are 08:00-17:00. If the arrival time is earlier than 08:00, the customer needs to wait until the bank opens to be served; If the customer arrives at the bank late (or exactly) 17:00:01, the customer is not serviced, and therefore the average waiting time for the customer is not calculated.
Output
For each test case, output the customer's average wait time, in minutes, and accurate to a decimal.
Ideas for solving problems
A typical simulation problem, and a simpler simulation than Pat 1014.
Automatically filters customers arriving after 17:00:00 when reading data.
Service in order of customer arrival, after the completion of customer service, update the window service completion time.
Customers Queue (service) each time the shortest service is completed.
The following conditions need to be considered:
-If the bank is not open, the customer needs to wait;
(and some of the situations described in "problems encountered")
Problems encountered
Several times WA, there are the following circumstances to consider
1. If all customers arrive after 17:00:00, the result is 0.0;
2. If all the current customers have completed the service, but the next customer has not arrived, need to wait for the window;
3. If the current customer does not need to wait, the window service completion time for the customer arrival time + service time; Otherwise, the window service completes the time that the previous customer completed + the customer service time.