1017 Queueing at Bank (25point(s))
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 10010;
const int maxk = 110;
int N, K;
struct Node{
int hh,mm,ss;
int time;
int process;
}customer[maxn];
bool cmp(Node a, Node b){
return a.time < b.time;
}
int window[maxk];
int sum = 0;
int main(){
scanf("%d %d", &N, &K);
for(int i=0; i<N; i++){
scanf("%d:%d:%d %d",&customer[i].hh, &customer[i].mm, &customer[i].ss, &customer[i].process);
customer[i].time = 3600*customer[i].hh + 60*customer[i].mm + customer[i].ss;
/*if(customer[i].time < 8*3600) {
sum += 8*3600 - customer[i].time;
customer[i].time = 8*3600; //这样会使先来后到的顺序信息消失,导致后续计算出错
}*/
if(customer[i].process>60) customer[i].process = 3600;
else customer[i].process *= 60;
}
sort(customer, customer+N, cmp);
fill(window, window+K, 8*60*60);
int i=0;
for(i=0; i<N; i++){
if(customer[i].time > 17*60*60) break;
//find window;
int next = window[0];
int index = 0;
for(int j=1; j<K; j++){
if(window[j] < next){
next = window[j];
index = j;
}
}
//arrage window;
if(next <= customer[i].time) {
window[index] = customer[i].time + customer[i].process;
} else {
sum += window[index] - customer[i].time;
window[index] += customer[i].process;
}
}
if(i!=0) printf("%.1lf\n", 1.0*sum/60.0/i);
else printf("0.0\n");
return 0;
}