注:只要顾客在工作时间到达,那么即使轮到他的时候银行已经下班,仍然要给他办理。
#include <stdio.h>
#include <algorithm>
#include <vector>
#define OPEN_TIME 8 * 3600
#define CLOSE_TIME 17 * 3600
using namespace std;
typedef struct Cus {
int comTime;
int proTime;
public:
Cus(int t, int s) {
comTime = t;
proTime = s;
}
} Cus;
typedef struct Win {
int finTime;
public:
Win(int t) {
finTime = t;
}
} Win;
bool comp1(Cus a, Cus b) {
return a.comTime < b.comTime;
}
bool comp2(Win a, Win b) {
return a.finTime < b.finTime;
}
vector<Cus> customers;
vector<Win> windows;
int main(int argc, char *argv[]) {
int n, k;
int i, j;
int h, m, s, t;
scanf("%d %d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d:%d:%d %d", &h, &m, &s, &t);
Cus c(h * 3600 + m * 60 + s, t * 60);
if (c.comTime <= CLOSE_TIME)
customers.push_back(c);
}
for (i = 0; i < k; i++) {
Win w(OPEN_TIME);
windows.push_back(w);
}
sort(customers.begin(), customers.end(), comp1);
float sumTime = 0.0;
float count = 0.0;
while (!customers.empty()) {
sort(windows.begin(), windows.end(), comp2);
// if (windows.front().finTime > CLOSE_TIME) break;这一句应当删除
if (windows.front().finTime < customers.front().comTime) {
windows.front().finTime = customers.front().comTime + customers.front().proTime;
} else {
sumTime += windows.front().finTime - customers.front().comTime;
windows.front().finTime += customers.front().proTime;
}
customers.erase(customers.begin());
count++;
}
if (count > 0)
printf("%.1f\n", sumTime / count / 60.0);
else
printf("0.0\n");
return 0;
}