64,649
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct node
{
int come, times;
}tempcustomer;
bool cmp(node a, node b) { //升序排
return a.come<b.come;
}
int main()
{
int n, k;
scanf_s("%d%d", &n, &k);
vector<node> custom;
for (int i = 0; i<n; i++) {
int hh, mm, ss, p;
scanf_s("%d:%d:%d %d", &hh, &mm, &ss, &p);
int cometime = hh * 3600 + mm * 60 + ss;
if (cometime>61200) continue;
tempcustomer = { cometime,p * 60 };
custom.push_back(tempcustomer);
}
sort(custom.begin(), custom.end(), cmp);
vector<int> window(k, 28800);
double result = 0.0;
for (int i = 0; i<custom.size(); i++) {
int tempindex = 0, minfinish = window[0];
for (int j = 1; j<k; j++) {
if (minfinish>window[j]) {
minfinish = window[j];
tempindex = j;
}
}
if (window[tempindex] <= custom[i].come) {
window[tempindex] = custom[i].come + custom[i].times;
}
else {
result += (window[tempindex] - custom[i].come);
window[tempindex] += custom[i].times;
}
}
if (custom.size() == 0) {
printf("0.0");
}
else {
printf("%.1f", result / 60.0 / custom.size());
}
return 0;
}