注意:
- 计算平均等待时间时应除以被银行服务的人数,而不是排队的总人数N,否则Case0:Wrong Answer
- 银行会服务完所有17点前开始排队的顾客,而不是到17点关门,否则Case5:Wrong Answer (Case5中最晚会服务到半夜零点半左右,这什么神仙银行!
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define OPEN 8*60*60
#define CLOSE 17*60*60
struct node{
int arr, pro;
};
bool cmp(node a, node b){
return a.arr < b.arr;
}
int getWindow(vector<int> w){
int j = 0;
for(int i = 1; i < w.size(); i++)
if(w[j] > w[i]) j = i;
return j;
}
int main(void){
int N, K;
scanf("%d %d", &N, &K);
vector<node> v(N);
vector<int> w(K, OPEN);
for(int i = 0; i < N; i++){
int hh, mm, ss, p;
scanf("%d:%d:%d %d", &hh, &mm, &ss, &p);
v[i].arr = hh*60*60 + mm*60 + ss;
v[i].pro = p*60;
}
sort(v.begin(), v.end(), cmp);
int wait = 0, i;
for(i = 0; i <N && v[i].arr <= CLOSE; i++){
int j = getWindow(w);
if(w[j] > v[i].arr)
wait += w[j]-v[i].arr, w[j] += v[i].pro;
else
w[j] = v[i].arr+v[i].pro;
}
printf("%.1f", 1.0*wait/60/i);
return 0;
}