#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 10010;
struct customer {
int arriveTime;
int processTime;
} Customer[MAXN];
struct window {
int startEmptyTime = 8 * 3600;
} Window[MAXN];
bool cmp1(customer a, customer b) {
return a.arriveTime < b.arriveTime;
}
bool cmp2(window a, window b) {
return a.startEmptyTime < b.startEmptyTime;
}
int main() {
int N, K;
scanf("%d%d",&N,&K);
for(int i=0; i<N; i++) {
int t1, t2, t3;
scanf("%d:%d:%d",&t1,&t2,&t3);
Customer[i].arriveTime = t1 * 3600 + t2 * 60 + t3; //秒计
int currentProcessTime;
scanf("%d",¤tProcessTime);
Customer[i].processTime = currentProcessTime * 60;
}
sort(Customer,Customer+N,cmp1);
int cnt = 0;
double TotalaitTime = 0.0;
for(int i=0; i<N; i++) {
if(Customer[i].arriveTime <= 17 * 3600) { //把下班之前已经受理的业务办完再下班
sort(Window,Window+K,cmp2); //是按照最空,而不是按照窗口的顺序
if(Window[0].startEmptyTime - Customer[i].arriveTime > 0) { //需要等待
TotalaitTime += Window[0].startEmptyTime - Customer[i].arriveTime;
Window[0].startEmptyTime += Customer[i].processTime;
} else { //无要等待
Window[0].startEmptyTime += Customer[i].processTime + (Customer[i].arriveTime - Window[0].startEmptyTime);
}
cnt ++;
}
}
printf("%0.1lf\n",TotalaitTime / cnt / 60);
return 0;
}
1017 Queueing at Bank (25)
最新推荐文章于 2021-10-15 17:18:30 发布