题意
假设一个银行有 K K K个窗口开发服务。在窗口前有一条黄线把等待区分为两部分,所有的客人必须在黄线外等候,直到轮到他或她能被可使用的窗口所服务。假定没有窗口只能被一个人所占用且不超过1个小时
Input Specification:
每组输入有一个测试点,对于每个测试点,第一行包含两个数字
N
N
N
(
≤
1
0
4
)
(\leq10^4)
(≤104)表示客人的总人数和
K
K
K
(
≤
100
)
(\leq100)
(≤100)表示窗口的数目。接下来又N行跟着每行包括两个时间,
H
H
:
M
M
:
S
S
HH:MM:SS
HH:MM:SS表示来到银行的时间,
P
P
P表示客人的服务时间,这里
H
H
HH
HH从[00,23],
M
M
MM
MM和
S
S
SS
SS为[00,59],假设没有两个客人同时到达
注意银行从早上8点到17点开放。任何早于8点来的都得等到8点,任何来的迟于17:00:01或在17:00:01的都不会被服务和计算到平均值内
Output Specification:
对于每个测试点,输出一行平均等待时间,以分钟表示,保留一位小数
思路
这道题有个大坑点和1014还不同,题目是说银行只在17点开放,晚于17点到达银行的是不会被记录在内的,但是!!!,在17点前到达银行但是轮到你服务的时候是在17点后你也是算进平均时间的,所以如果你用for循环模拟从8点到17点一秒一秒计算每个人的等待时间这样早已17点来但是晚于17点被服务的就不会算进去,这就是最后一个测试点里面包含的。
还有要注意合法人数为0的情况
#include <bits/stdc++.h>
using namespace std;
struct node
{
int h;
int m;
int s;
int t;
int p;
};
vector<node>a;
char str[100];
bool cmp(node a,node b)
{
return a.t<b.t;
}
int b[105];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=0; i<n; i++)
{
node tmp;
scanf("%s%d",str,&tmp.p);
tmp.p=tmp.p*60;
tmp.h=(str[0]-'0')*10+str[1]-'0';
tmp.m=(str[3]-'0')*10+str[4]-'0';
tmp.s=(str[6]-'0')*10+str[7]-'0';
tmp.t=tmp.h*60*60+tmp.m*60+tmp.s;
if(tmp.t<61200)
a.push_back(tmp);
}
sort(a.begin(),a.end(),cmp);
double sum=0;
int cnt=0;
double sum2=0;
for(int i=28800;; i++)
{
for(int j=0; j<k; j++)
{
if(b[j]!=0)
b[j]--;
if(b[j]==0&&a.size()!=0&&i>=a[0].t)
{
if(a.size()!=0)
{
cnt++;
sum+=i-a[0].t;
b[j]=min(a[0].p,60*60);
}
if(a.size()!=0)
a.erase(a.begin());
}
}
if(a.size()==0)
break;
}
if(cnt!=0)
printf("%.1f\n",sum/60/cnt);
else
printf("0.0\n");
return 0;
}