#include <stdio.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
struct Customer
{
int hours;
int minutes;
int seconds;
int process;
int totalTime;
} ctm[10010];
struct Window
{
int time;
Customer ctm;
};
queue<Window> window[110];
int n, K, num;
int TT = 8 * 60 * 60;
bool cmp(Customer a, Customer b)
{
return a.totalTime < b.totalTime;
}
int timeWait[10010];
int main()
{
int i, count, j;
while(scanf("%d %d", &n, &K) != EOF)
{
memset(timeWait, 0, sizeof(timeWait));
for(i = 0; i < n; i++)
{
scanf("%d:%d:%d %d", &ctm[i].hours, &ctm[i].minutes, &ctm[i].seconds, &ctm[i].process);
ctm[i].totalTime = ctm[i].hours * 60 * 60 + ctm[i].minutes * 60 + ctm[i].seconds;
if(ctm[i].process > 60)
ctm[i].process = 60;
}
sort(ctm, ctm + n, cmp);
count = 0;
num = 0;
Window wd, tmp;
for(i = 0; i < K; i++)
{
wd.ctm = ctm[i];
if(ctm[i].totalTime < TT)
{
wd.time = TT + ctm[i].process * 60;
}
else
wd.time = ctm[i].process * 60 + ctm[i].totalTime;
timeWait[i] = wd.time - ctm[i].totalTime - ctm[i].process * 60;
num = i;
window[i+1].push(wd);
}
for(; i < n; i++)
{
wd = window[1].front();
int min = wd.time, index = 1;
for(j = 2; j <= K; j++)
{
wd = window[j].front();
if(wd.time < min)
{
min = wd.time;
index = j;
}
}
if(ctm[i].totalTime <= 17 * 60 * 60)
{
tmp.ctm = ctm[i];
wd = window[index].front();
window[index].pop();
if(wd.time > ctm[i].totalTime) //之前一直有个case过不了,发现题目意思理解错了。即,客户只要在17:00之前到达银行,那么即使窗口的结束时间在17:00以后,那银行还是需要给客户服务的
tmp.time = wd.time + ctm[i].process * 60;
else if(ctm[i].totalTime >= wd.time)
tmp.time = ctm[i].totalTime + ctm[i].process * 60;
window[index].push(tmp);
timeWait[i] = tmp.time - ctm[i].totalTime - ctm[i].process * 60;
num = i;
}
}
for(i= 0; i < n; i++)
count += timeWait[i];
printf("%.1lf\n", 1.0*count/60.0/(num+1));
}
return 0;
}
pat 1017
最新推荐文章于 2021-03-03 21:21:37 发布