返回目录![在这里插入图片描述](https://img-blog.csdnimg.cn/20200418190718438.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ExOTIwOTkzMTY1,size_16,color_FFFFFF,t_70)
题意
有N个客户,K个窗口。给出每个客户的到达时间和服务时长,如果所有窗口都被占用,那么客户将在黄线外进行排队(只有一个队);否则,如果有窗口无人服务,那么由队列的第一个客户前往接受服务。求客户的平均等待时长。注意,银行开放时间为08:00~ 17:00, 在08:00之前到达的需要等待,在17:00之后(不含17:00) 还未被服务的客户将不被计算在内。另外,超过1h的服务时长会被缩短为1h。
样例(可复制)
7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10
//output
8.2
注意点
- 为了方便时间的处理,将时间转换为以s为单位。
- 本题没有在17点前到达的客户数为0的测试点。
- 17.00.00的客户也要服务。
#include <bits/stdc++.h>
using namespace std;
struct cus{
int come,serve;
}per;
int n,k,totalt=0;
vector<cus> custom;//存放在17点前出现的客户
int endtime[110];//存放服务窗口的结束时间
int gettime(int h,int m,int s){
return h*3600+m*60+s;
}
bool cmp(cus a,cus b){
return a.come<b.come;
}
int main(){
cin>>n>>k;
int hh,mm,ss;
int st=gettime(8,0,0),ed=gettime(17,0,0);
for(int i=0;i<n;i++){
scanf("%d:%d:%d %d",&hh,&mm,&ss,&per.serve);
if(gettime(hh,mm,ss)>ed)continue;//如果超过17.00.00则跳过
per.come=gettime(hh,mm,ss);
per.serve=min(3600,60*per.serve);//超过1h则按1h计
custom.push_back(per);
}
sort(custom.begin(),custom.end(),cmp);
fill(endtime,endtime+k,st);//初始化服务结束时间为8.00.00
for(int i=0;i<custom.size();i++){//循环一次处理一个客户
int idx,mintime=INT_MAX;
for(int j=0;j<k;j++){//找合适的服务窗口
if(endtime[j]<mintime){
mintime=endtime[j];
idx=j;
}
}
if(endtime[idx]<=custom[i].come){
endtime[idx]=custom[i].come+custom[i].serve;
}else{
totalt+=(endtime[idx]-custom[i].come);
endtime[idx]+=custom[i].serve;
}
}
printf("%.1f",totalt/60.0/custom.size());
return 0;
}