##### 10、银行排队✔
时间用秒计时;堆里存的是当前窗口的预计的开始服务的时间;
对于每个客户,根据now 与 peoples[i].arrive_time 判断来早了还是来晚了。
来早了,无等待时间,并加入堆中,他被服务完的时刻是peoples[i].server_time + now
来晚了,新增等待时间,加入堆中。他被服务完的时刻是peoples[i].server_time + peoples[i].arrive_time
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N = 10000+10;
int n,k;
struct People{
int arrive_time;
int server_time;
bool operator < (People x){
return arrive_time<x.arrive_time;
}
}peoples[N];
int main(){
cin>>n>>k;
for(int i=0;i<n;i++){
int h,m,s,l;
scanf("%d:%d:%d %d",&h,&m,&s,&l);
int arrive_time,server_time;
arrive_time = h*3600 + m*60 + s;
server_time = min(l,60) * 60;
peoples[i] = {arrive_time,server_time};
}
sort(peoples,peoples+n);
priority_queue<int,vector<int>,greater<int> > windows; //堆里存的是当前窗口的预计的开始服务的时间
for(int i=0;i<k;i++) windows.push(8*3600);
int wait_time=0;
int ignore=0;
for(int i=0;i<n;i++){
if(peoples[i].arrive_time > 17*3600) {
ignore++;
continue;
}
int now = windows.top();windows.pop();
if(now >= peoples[i].arrive_time){
wait_time += now - peoples[i].arrive_time;
windows.push(now + peoples[i].server_time);
}
else {
windows.push(peoples[i].arrive_time + peoples[i].server_time);
}
}
printf("%.1lf\n",(double)(wait_time )/60.0 /(n-ignore) );
}