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 (<=10000) - 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:
7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10
Sample Output:
8.2
#include<cstdio>
#include<cstring>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cctype>
#include<vector>
#include<iomanip>
#include<queue>
#include<stack>
#include<cassert>
#define INF 0x3f3f3f3f
#define max(x,y) x > y ? x : y
#define min(x,y) x < y ? x : y
using namespace std;
int Time = 0;
int ans = 0, cnt = 0;
int n, k, h, m, s, c, t;
struct customer{
int arriving_time, cost, ending_time;
customer(int t, int c){
arriving_time = t;
cost = c;
ending_time = 0;
}
};
struct cmp1{
bool operator()(const customer &a, const customer &b)const{
return a.arriving_time > b.arriving_time;
}
};
struct cmp2{
bool operator()(const customer &a, const customer &b)const{
return a.ending_time > b.ending_time;
}
};
priority_queue<customer, vector<customer>, cmp1> q1;
priority_queue<customer, vector<customer>, cmp2> q2;
int main(){
cin>>n>>k;
for(int i = 0; i < n; i ++){
scanf("%d:%d:%d%d",&h,&m,&s,&c);
if(c > 60) c = 60;
t = (h-8) * 60 * 60 + m * 60 + s;
if(t > 9 * 60 * 60) continue;
q1.push(customer(t,c * 60));
}
for(int i = 0; i < k; i ++) q2.push(customer(0,0));
while(!q1.empty()){
cnt ++;
customer p = q1.top();
q1.pop();
customer w = q2.top();
q2.pop();
if(w.ending_time > p.arriving_time){
p.ending_time = w.ending_time + p.cost;
ans += w.ending_time - p.arriving_time;
}
else p.ending_time = p.arriving_time + p.cost;
q2.push(p);
}
printf("%.1f",double(ans) / cnt / 60);
}

本文介绍了一个银行排队系统的模拟算法,该算法通过优先级队列来模拟顾客到达与服务过程,计算每位顾客的平均等待时间。输入包括顾客总数、窗口数量及顾客到达时间和处理时间。
361

被折叠的 条评论
为什么被折叠?



