列两个队列:
排队的人
服务的窗口
坑点:在17点前到达银行的都算进平均时间
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
const int inf = 0x3f3f3f3f;
const int ST = 8*60*60;
const int ET = 17*60*60;
struct P {
int g;
int u;
friend bool operator<(const P&A, const P&B) {
if(A.g == B.g)
return A.u > B.u;
return A.g > B.g;
}
} tmp;
priority_queue<int, vector<int>, greater<int> >ans;
priority_queue<P> p;
int main() {
int n, m;
cin >> n >> m;
for(int i=0; i<n; i++) {
int h, m, s, u;
scanf("%d:%d:%d %d", &h, &m, &s, &u);
tmp.g = h*3600+m*60+s;
if(u>60) u = 60;
tmp.u = u*60;
p.push(tmp);
}
int cnt = 0, sum=0;
while(!p.empty()) {
tmp = p.top();
p.pop();
int et;
if(tmp.g < ST) {
sum += (ST-tmp.g);
tmp.g = ST;
} else if(tmp.g > ET) {
continue;
}
if(ans.size() < m) {
et = tmp.g+tmp.u;
} else {
et = ans.top();
ans.pop();
/*
if(et > ET) { //因为是优先队列
break;
}*/
et = max(et, tmp.g);
sum += (et-tmp.g);
et += tmp.u;
}
cnt++;
ans.push(et);
}
printf("%.1f\n", (sum/(cnt*60.0)));
return 0;
}